@@ -25,9 +25,11 @@ import (
25
25
)
26
26
27
27
type bootstrapAPIResponse struct {
28
- CaURL string `json:"url"`
29
- Fingerprint string `json:"fingerprint"`
30
- RedirectURL string `json:"redirect-url"`
28
+ CaURL string `json:"url"`
29
+ Fingerprint string `json:"fingerprint"`
30
+ RedirectURL string `json:"redirect-url"`
31
+ Provisioner string `json:"provisioner"`
32
+ MinPasswordLength int `json:"min-password-length"`
31
33
}
32
34
33
35
// UseContext returns true if contexts should be used, false otherwise.
@@ -55,6 +57,20 @@ type bootstrapOption func(bc *bootstrapContext)
55
57
type bootstrapContext struct {
56
58
defaultContextName string
57
59
redirectURL string
60
+ provisioner string
61
+ minPasswordLength int
62
+ }
63
+
64
+ func withProvisioner (provisioner string ) bootstrapOption {
65
+ return func (bc * bootstrapContext ) {
66
+ bc .provisioner = provisioner
67
+ }
68
+ }
69
+
70
+ func withMinPasswordLength (minLength int ) bootstrapOption {
71
+ return func (bc * bootstrapContext ) {
72
+ bc .minPasswordLength = minLength
73
+ }
58
74
}
59
75
60
76
func withDefaultContextValues (context string ) bootstrapOption {
@@ -70,10 +86,12 @@ func withRedirectURL(r string) bootstrapOption {
70
86
}
71
87
72
88
type bootstrapConfig struct {
73
- CA string `json:"ca-url"`
74
- Fingerprint string `json:"fingerprint"`
75
- Root string `json:"root"`
76
- Redirect string `json:"redirect-url"`
89
+ CA string `json:"ca-url"`
90
+ Fingerprint string `json:"fingerprint"`
91
+ Root string `json:"root"`
92
+ Redirect string `json:"redirect-url,omitempty"`
93
+ Provisioner string `json:"provisioner,omitempty"`
94
+ MinPasswordLength int `json:"min-password-length,omitempty"`
77
95
}
78
96
79
97
func bootstrap (ctx * cli.Context , caURL , fingerprint string , opts ... bootstrapOption ) error {
@@ -126,16 +144,16 @@ func bootstrap(ctx *cli.Context, caURL, fingerprint string, opts ...bootstrapOpt
126
144
rootFile := pki .GetRootCAPath ()
127
145
configFile := step .DefaultsFile ()
128
146
129
- if err = os .MkdirAll (filepath .Dir (rootFile ), 0700 ); err != nil {
147
+ if err = os .MkdirAll (filepath .Dir (rootFile ), 0o700 ); err != nil {
130
148
return errs .FileError (err , rootFile )
131
149
}
132
150
133
- if err = os .MkdirAll (filepath .Dir (configFile ), 0700 ); err != nil {
151
+ if err = os .MkdirAll (filepath .Dir (configFile ), 0o700 ); err != nil {
134
152
return errs .FileError (err , configFile )
135
153
}
136
154
137
155
// Serialize root
138
- _ , err = pemutil .Serialize (resp .RootPEM .Certificate , pemutil .ToFile (rootFile , 0600 ))
156
+ _ , err = pemutil .Serialize (resp .RootPEM .Certificate , pemutil .ToFile (rootFile , 0o600 ))
139
157
if err != nil {
140
158
return err
141
159
}
@@ -148,12 +166,19 @@ func bootstrap(ctx *cli.Context, caURL, fingerprint string, opts ...bootstrapOpt
148
166
}
149
167
150
168
// Serialize defaults.json
151
- b , err := json . MarshalIndent ( bootstrapConfig {
169
+ bootConf := bootstrapConfig {
152
170
CA : caURL ,
153
171
Fingerprint : fingerprint ,
154
172
Root : pki .GetRootCAPath (),
155
173
Redirect : bc .redirectURL ,
156
- }, "" , " " )
174
+ }
175
+ if bc .minPasswordLength > 0 {
176
+ bootConf .MinPasswordLength = bc .minPasswordLength
177
+ }
178
+ if bc .provisioner != "" {
179
+ bootConf .Provisioner = bc .provisioner
180
+ }
181
+ b , err := json .MarshalIndent (bootConf , "" , " " )
157
182
if err != nil {
158
183
return errors .Wrap (err , "error marshaling defaults.json" )
159
184
}
@@ -162,7 +187,7 @@ func bootstrap(ctx *cli.Context, caURL, fingerprint string, opts ...bootstrapOpt
162
187
ctx .Set ("fingerprint" , fingerprint )
163
188
ctx .Set ("root" , rootFile )
164
189
165
- if err := utils .WriteFile (configFile , b , 0644 ); err != nil {
190
+ if err := utils .WriteFile (configFile , b , 0o644 ); err != nil {
166
191
return err
167
192
}
168
193
@@ -171,12 +196,12 @@ func bootstrap(ctx *cli.Context, caURL, fingerprint string, opts ...bootstrapOpt
171
196
if step .Contexts ().Enabled () {
172
197
profileDefaultsFile := step .ProfileDefaultsFile ()
173
198
174
- if err := os .MkdirAll (filepath .Dir (profileDefaultsFile ), 0700 ); err != nil {
199
+ if err := os .MkdirAll (filepath .Dir (profileDefaultsFile ), 0o700 ); err != nil {
175
200
return errs .FileError (err , profileDefaultsFile )
176
201
}
177
202
178
203
if _ , err := os .Stat (profileDefaultsFile ); os .IsNotExist (err ) {
179
- if err := os .WriteFile (profileDefaultsFile , []byte ("{}" ), 0600 ); err != nil {
204
+ if err := os .WriteFile (profileDefaultsFile , []byte ("{}" ), 0o600 ); err != nil {
180
205
return errs .FileError (err , profileDefaultsFile )
181
206
}
182
207
ui .Printf ("The profile configuration has been saved in %s.\n " , profileDefaultsFile )
@@ -254,9 +279,17 @@ func BootstrapTeamAuthority(ctx *cli.Context, team, teamAuthority string) error
254
279
r .RedirectURL = "https://smallstep.com/app/teams/sso/success"
255
280
}
256
281
257
- return bootstrap (ctx , r .CaURL , r .Fingerprint ,
258
- withDefaultContextValues (teamAuthority + "." + team ),
259
- withRedirectURL (r .RedirectURL ))
282
+ bootOpts := []bootstrapOption {
283
+ withDefaultContextValues (teamAuthority + "." + team ),
284
+ withRedirectURL (r .RedirectURL ),
285
+ }
286
+ if r .Provisioner != "" {
287
+ bootOpts = append (bootOpts , withProvisioner (r .Provisioner ))
288
+ }
289
+ if r .MinPasswordLength > 0 {
290
+ bootOpts = append (bootOpts , withMinPasswordLength (r .MinPasswordLength ))
291
+ }
292
+ return bootstrap (ctx , r .CaURL , r .Fingerprint , bootOpts ... )
260
293
}
261
294
262
295
// BootstrapAuthority bootstraps an authority using only the caURL and fingerprint.
@@ -268,7 +301,7 @@ func BootstrapAuthority(ctx *cli.Context, caURL, fingerprint string) (err error)
268
301
}
269
302
}
270
303
271
- var opts = []bootstrapOption {
304
+ opts : = []bootstrapOption {
272
305
withDefaultContextValues (caHostname ),
273
306
}
274
307
0 commit comments