@@ -25,9 +25,11 @@ import (
2525)
2626
2727type 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+ MinEncryptionPasswordLength int `json:"min-encryption-password-length"`
3133}
3234
3335// UseContext returns true if contexts should be used, false otherwise.
@@ -53,8 +55,22 @@ func WarnContext() {
5355type bootstrapOption func (bc * bootstrapContext )
5456
5557type bootstrapContext struct {
56- defaultContextName string
57- redirectURL string
58+ defaultContextName string
59+ redirectURL string
60+ provisioner string
61+ minEncryptionPasswordLength int
62+ }
63+
64+ func withProvisioner (provisioner string ) bootstrapOption {
65+ return func (bc * bootstrapContext ) {
66+ bc .provisioner = provisioner
67+ }
68+ }
69+
70+ func withMinEncryptionPasswordLength (minLength int ) bootstrapOption {
71+ return func (bc * bootstrapContext ) {
72+ bc .minEncryptionPasswordLength = minLength
73+ }
5874}
5975
6076func withDefaultContextValues (context string ) bootstrapOption {
@@ -70,10 +86,12 @@ func withRedirectURL(r string) bootstrapOption {
7086}
7187
7288type 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"`
93+ Provisioner string `json:"provisioner"`
94+ MinEncryptionPasswordLength int `json:"min-encryption-password-length"`
7795}
7896
7997func bootstrap (ctx * cli.Context , caURL , fingerprint string , opts ... bootstrapOption ) error {
@@ -126,16 +144,16 @@ func bootstrap(ctx *cli.Context, caURL, fingerprint string, opts ...bootstrapOpt
126144 rootFile := pki .GetRootCAPath ()
127145 configFile := step .DefaultsFile ()
128146
129- if err = os .MkdirAll (filepath .Dir (rootFile ), 0700 ); err != nil {
147+ if err = os .MkdirAll (filepath .Dir (rootFile ), 0o700 ); err != nil {
130148 return errs .FileError (err , rootFile )
131149 }
132150
133- if err = os .MkdirAll (filepath .Dir (configFile ), 0700 ); err != nil {
151+ if err = os .MkdirAll (filepath .Dir (configFile ), 0o700 ); err != nil {
134152 return errs .FileError (err , configFile )
135153 }
136154
137155 // Serialize root
138- _ , err = pemutil .Serialize (resp .RootPEM .Certificate , pemutil .ToFile (rootFile , 0600 ))
156+ _ , err = pemutil .Serialize (resp .RootPEM .Certificate , pemutil .ToFile (rootFile , 0o600 ))
139157 if err != nil {
140158 return err
141159 }
@@ -148,12 +166,19 @@ func bootstrap(ctx *cli.Context, caURL, fingerprint string, opts ...bootstrapOpt
148166 }
149167
150168 // Serialize defaults.json
151- b , err := json . MarshalIndent ( bootstrapConfig {
169+ bootConf := bootstrapConfig {
152170 CA : caURL ,
153171 Fingerprint : fingerprint ,
154172 Root : pki .GetRootCAPath (),
155173 Redirect : bc .redirectURL ,
156- }, "" , " " )
174+ }
175+ if bc .minEncryptionPasswordLength > 0 {
176+ bootConf .MinEncryptionPasswordLength = bc .minEncryptionPasswordLength
177+ }
178+ if bc .provisioner != "" {
179+ bootConf .Provisioner = bc .provisioner
180+ }
181+ b , err := json .MarshalIndent (bootConf , "" , " " )
157182 if err != nil {
158183 return errors .Wrap (err , "error marshaling defaults.json" )
159184 }
@@ -162,7 +187,7 @@ func bootstrap(ctx *cli.Context, caURL, fingerprint string, opts ...bootstrapOpt
162187 ctx .Set ("fingerprint" , fingerprint )
163188 ctx .Set ("root" , rootFile )
164189
165- if err := utils .WriteFile (configFile , b , 0644 ); err != nil {
190+ if err := utils .WriteFile (configFile , b , 0o644 ); err != nil {
166191 return err
167192 }
168193
@@ -171,12 +196,12 @@ func bootstrap(ctx *cli.Context, caURL, fingerprint string, opts ...bootstrapOpt
171196 if step .Contexts ().Enabled () {
172197 profileDefaultsFile := step .ProfileDefaultsFile ()
173198
174- if err := os .MkdirAll (filepath .Dir (profileDefaultsFile ), 0700 ); err != nil {
199+ if err := os .MkdirAll (filepath .Dir (profileDefaultsFile ), 0o700 ); err != nil {
175200 return errs .FileError (err , profileDefaultsFile )
176201 }
177202
178203 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 {
180205 return errs .FileError (err , profileDefaultsFile )
181206 }
182207 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
254279 r .RedirectURL = "https://smallstep.com/app/teams/sso/success"
255280 }
256281
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 .MinEncryptionPasswordLength > 0 {
290+ bootOpts = append (bootOpts , withMinEncryptionPasswordLength (r .MinEncryptionPasswordLength ))
291+ }
292+ return bootstrap (ctx , r .CaURL , r .Fingerprint , bootOpts ... )
260293}
261294
262295// BootstrapAuthority bootstraps an authority using only the caURL and fingerprint.
@@ -268,7 +301,7 @@ func BootstrapAuthority(ctx *cli.Context, caURL, fingerprint string) (err error)
268301 }
269302 }
270303
271- var opts = []bootstrapOption {
304+ opts : = []bootstrapOption {
272305 withDefaultContextValues (caHostname ),
273306 }
274307
0 commit comments