Add configuration settings for Argon2 password KDF (#217)
* Bump generated proto code * Add argon2 conf sql and proto files * Add generated code for argon2 conf * Add Resources for Argon2 configuration * Add get and set Configuration to repository * Add current config reference to AuthMethod * Fix authmethod_test * Fix TestAccount_New * Add WithConfiguration to options * Add sql views for current configuration * Fix SetTableName * Remove duplicate testAccounts function * Make tests clearer * Fix comment * Rename test variable * Use NewPrivateId function for private Ids * Refactor: rename public_id to private_id for password_conf and password_credential * Remove bad comment * Check if embedded argon2 configuration is nil * Add checks around the WithConfiguration option * Use spaces not tabs in proto file * Add doc to explain choice of oplog ticket * Verify oplog in test
This commit is contained in:
1 parent
c3c07f1556
commit
c163d790a4
23 files changed
+1613
-64
No files matched your search
@@ -13,6 +13,9 @@ import (
|
||||
// contain a valid ScopeId. m must not contain a PublicId. The PublicId is
|
||||
// generated and assigned by this method.
|
||||
//
|
||||
// WithConfiguration is the only valid option. All other options are
|
||||
// ignored.
|
||||
//
|
||||
// Both m.Name and m.Description are optional. If m.Name is set, it must be
|
||||
// unique within m.ScopeId.
|
||||
func (r *Repository) CreateAuthMethod(ctx context.Context, m *AuthMethod, opt ...Option) (*AuthMethod, error) {
|
||||
@@ -36,9 +39,29 @@ func (r *Repository) CreateAuthMethod(ctx context.Context, m *AuthMethod, opt ..
|
||||
}
|
||||
m.PublicId = id
|
||||
|
||||
opts := getOpts(opt...)
|
||||
c, ok := opts.withConfig.(*Argon2Configuration)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("create: password auth method: unknown configuration: %w", ErrUnsupportedConfiguration)
|
||||
}
|
||||
if err := c.validate(); err != nil {
|
||||
return nil, fmt.Errorf("create: password auth method: %w", err)
|
||||
}
|
||||
|
||||
c.PrivateId, err = newArgon2ConfigurationId()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create: password auth method: %w", err)
|
||||
}
|
||||
m.PasswordConfId, c.PasswordMethodId = c.PrivateId, m.PublicId
|
||||
|
||||
var newAuthMethod *AuthMethod
|
||||
var newArgon2Conf *Argon2Configuration
|
||||
_, err = r.writer.DoTx(ctx, db.StdRetryCnt, db.ExpBackoff{},
|
||||
func(_ db.Reader, w db.Writer) error {
|
||||
newArgon2Conf = c.clone()
|
||||
if err := w.Create(ctx, newArgon2Conf, db.WithOplog(r.wrapper, c.oplog(oplog.OpType_OP_TYPE_CREATE))); err != nil {
|
||||
return err
|
||||
}
|
||||
newAuthMethod = m.clone()
|
||||
return w.Create(ctx, newAuthMethod, db.WithOplog(r.wrapper, m.oplog(oplog.OpType_OP_TYPE_CREATE)))
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user