|
4 | 4 | package options |
5 | 5 |
|
6 | 6 | import ( |
7 | | - "errors" |
8 | 7 | "fmt" |
9 | | - "net/url" |
10 | 8 |
|
11 | 9 | "github.com/spf13/cobra" |
12 | 10 |
|
13 | 11 | "github.com/carabiner-dev/signer/internal/tuf" |
| 12 | + "github.com/carabiner-dev/signer/sigstore" |
14 | 13 | ) |
15 | 14 |
|
16 | 15 | // Sigstore options to control how signer handles signing with sigstore |
17 | 16 | type Sigstore struct { |
18 | | - // Embed the tuf options struct |
19 | | - tuf.TufOptions |
20 | | - |
21 | | - Timestamp bool |
22 | | - |
23 | | - // AppendToRekor controls if the signing operation is recorded into the |
24 | | - // transparency log. |
25 | | - AppendToRekor bool `json:"rekor-append"` |
26 | | - DisableSTS bool |
27 | | - |
28 | | - // FulcioURL url of the Fulcio CA (defaults to the public good instance) |
29 | | - FulcioURL string `json:"fulcio-url"` |
30 | | - |
31 | | - // RekorURL url of the Rekor transparency log (defaults to the public good instance) |
32 | | - RekorURL string `json:"rekor-url"` |
33 | | - |
34 | | - // Hide the OIDC options in the CLI --help |
35 | | - HideOIDCOptions bool |
36 | | - // FlagPrefix adds a prefix to the CLI strings, these help grouping them |
37 | | - FlagPrefix string |
38 | | - |
39 | | - // OidcRedirectURL defines the URL that the browser will redirect to. |
40 | | - // if the port is set to 0, bind will randomize it to a high number |
41 | | - // port before starting the OIDC flow. |
42 | | - OidcRedirectURL string `json:"oidc-redirect-url"` |
43 | | - |
44 | | - // OIDC token issuer endpoint |
45 | | - OidcIssuer string `json:"oidc-issuer"` |
46 | | - |
47 | | - // Client ID to stamp on the tokens |
48 | | - OidcClientID string `json:"oidc-client-id"` |
49 | | - |
50 | | - // Client secret to pass in OIDC calls |
51 | | - OidcClientSecret string `json:"oidc-client-secret"` |
52 | | - |
53 | | - // Time stamp verification options |
54 | | - |
55 | | - // Look for a signed timestamp in the cert and verify with the CTLog Auth |
56 | | - RequireCTlog bool `json:"require-ct-log"` |
57 | | - // Verify the cert validity in the transparency log |
58 | | - RequireTlog bool `json:"require-tlog"` |
59 | | - // Verify the certificate validity time with a signed timestamp |
60 | | - RequireSignedTimestamps bool `json:"require-signed-timestamps"` |
61 | | - // Allow no timestamp, for keys instead of certs |
62 | | - RequireObserverTimestamp bool `json:"require-observer-timestamp"` |
| 17 | + sigstore.Instance |
63 | 18 | } |
64 | 19 |
|
65 | 20 | // Ensure the options have the required OIDC fields |
66 | 21 | func (s *Sigstore) ValidateOIDC() error { |
67 | | - errs := []error{} |
68 | | - if s.OidcClientID == "" { |
69 | | - errs = append(errs, errors.New("OIDC client ID is missing")) |
70 | | - } |
71 | | - |
72 | | - if s.OidcIssuer == "" { |
73 | | - errs = append(errs, errors.New("OIDC issuer URL missing")) |
74 | | - } |
75 | | - |
76 | | - if s.OidcRedirectURL == "" { |
77 | | - errs = append(errs, errors.New("OIDC redirect URL missing")) |
78 | | - } |
79 | | - return errors.Join(errs...) |
| 22 | + return s.Instance.ValidateOIDC() |
80 | 23 | } |
81 | 24 |
|
82 | 25 | var DefaultSigstore = Sigstore{ |
83 | | - Timestamp: true, |
84 | | - AppendToRekor: true, |
85 | | - |
86 | | - TufOptions: tuf.TufOptions{ |
87 | | - TufRootURL: "https://tuf-repo-cdn.sigstore.dev", |
| 26 | + Instance: sigstore.Instance{ |
| 27 | + Timestamp: true, |
| 28 | + AppendToRekor: true, |
| 29 | + |
| 30 | + TufOptions: tuf.TufOptions{ |
| 31 | + TufRootURL: "https://tuf-repo-cdn.sigstore.dev", |
| 32 | + }, |
| 33 | + |
| 34 | + HideOIDCOptions: true, |
| 35 | + OidcRedirectURL: "http://localhost:0/auth/callback", |
| 36 | + OidcIssuer: "https://oauth2.sigstore.dev/auth", |
| 37 | + OidcClientID: "sigstore", |
| 38 | + |
| 39 | + // URLs default the public good instances |
| 40 | + FulcioURL: "https://fulcio.sigstore.dev", |
| 41 | + RekorURL: "https://rekor.sigstore.dev", |
| 42 | + |
| 43 | + RequireCTlog: true, |
| 44 | + RequireTlog: true, |
| 45 | + RequireObserverTimestamp: true, |
88 | 46 | }, |
89 | | - |
90 | | - HideOIDCOptions: true, |
91 | | - OidcRedirectURL: "http://localhost:0/auth/callback", |
92 | | - OidcIssuer: "https://oauth2.sigstore.dev/auth", |
93 | | - OidcClientID: "sigstore", |
94 | | - |
95 | | - // URLs default the public good instances |
96 | | - FulcioURL: "https://fulcio.sigstore.dev", |
97 | | - RekorURL: "https://rekor.sigstore.dev", |
98 | | - |
99 | | - RequireCTlog: true, |
100 | | - RequireTlog: true, |
101 | | - RequireObserverTimestamp: true, |
102 | 47 | } |
103 | 48 |
|
104 | 49 | // ValidateTimestamps |
105 | 50 | func (s *Sigstore) ValidateTimestamps() error { |
106 | | - if !s.RequireCTlog && !s.RequireTlog && !s.RequireObserverTimestamp && !s.RequireSignedTimestamps { |
107 | | - return errors.New("at least one method to check timestamps must be set") |
108 | | - } |
109 | | - return nil |
| 51 | + return s.Instance.ValidateTimestamps() |
110 | 52 | } |
111 | 53 |
|
112 | 54 | // ValidateSigner check the options required to sign |
113 | 55 | func (s *Sigstore) ValidateSigner() error { |
114 | | - errs := []error{ |
115 | | - s.ValidateOIDC(), |
116 | | - } |
117 | | - if s.RekorURL == "" { |
118 | | - if s.AppendToRekor { |
119 | | - errs = append(errs, errors.New("rekor url not set (and append to rekor is set)")) |
120 | | - } |
121 | | - } else { |
122 | | - if _, err := url.Parse(s.RekorURL); err != nil { |
123 | | - errs = append(errs, fmt.Errorf("invalid Rekor URL")) |
124 | | - } |
125 | | - } |
126 | | - if s.FulcioURL == "" { |
127 | | - errs = append(errs, errors.New("fulcio url not set")) |
128 | | - } else { |
129 | | - if _, err := url.Parse(s.RekorURL); err != nil { |
130 | | - errs = append(errs, fmt.Errorf("invalid Rekor URL")) |
131 | | - } |
132 | | - } |
133 | | - return errors.Join(errs...) |
| 56 | + return s.Instance.ValidateSigner() |
134 | 57 | } |
135 | 58 |
|
136 | 59 | func (s *Sigstore) ValidateVerifier() error { |
137 | | - errs := []error{ |
138 | | - s.ValidateTimestamps(), |
139 | | - } |
140 | | - if s.FulcioURL == "" { |
141 | | - errs = append(errs, errors.New("fulcio url not set")) |
142 | | - } else { |
143 | | - if _, err := url.Parse(s.RekorURL); err != nil { |
144 | | - errs = append(errs, fmt.Errorf("invalid Rekor URL value")) |
145 | | - } |
146 | | - } |
147 | | - return errors.Join(errs...) |
| 60 | + return s.Instance.ValidateVerifier() |
148 | 61 | } |
149 | 62 |
|
150 | 63 | // Validate checks the integrity of the sigstore options |
|
0 commit comments