Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

add SMS signing keys at the DB layer #1649

Merged
merged 3 commits into from
Jan 21, 2021
Merged

Conversation

mikehelmick
Copy link
Contributor

towards #1640

Proposed Changes

  • Add new SMSSiginingKey model
  • Create ManagedKey interface
  • Refactor realm key management to work on multiple type of managed keys

Release Note

Add database model for managed keys for signing SMS messages.

@googlebot googlebot added the cla: yes Auto: added by CLA bot when all committers have signed a CLA. label Jan 21, 2021
// IsActive() returns true if this key is active
IsActive() bool

SetRealmID(id uint)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function should be a separate interface, since some managed keys will not be realm specific, right? (Like system keys?) Or do you plan to use a realmID == 0 for those cases like we do for audit logs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduced RealmManagedKey - moved SetRealmID there.

this opens up extending ManagedKey to token signing keys in a follow up.

pkg/database/migrations.go Outdated Show resolved Hide resolved
deleted_at TIMESTAMP WITH TIME ZONE,
realm_id INTEGER,
key_id TEXT,
active BOOLEAN,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should create an index that ensures only one value for active can exist in the scope of a realm_id (there's some other tables that have this, it's a conditional index)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please double check my index statement

pkg/database/realm.go Outdated Show resolved Hide resolved
pkg/database/realm.go Outdated Show resolved Hide resolved
pkg/database/realm.go Outdated Show resolved Hide resolved
pkg/database/realm.go Outdated Show resolved Hide resolved
return r.createdManagedSigningKey(ctx, db, r.SMSSigningKeyID(), "sms_signing_keys", "SMS", newKey)
}

func (r *Realm) createdManagedSigningKey(ctx context.Context, db *Database, keyID, table, purpose string, signingKey ManagedKey) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of passing in purpose, you can use %T on the signingKey param in the errors. It seems that's the only purpose for passing in purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved Table() and Purpose() to methods on the ManagedKey interface.

pkg/database/sms_signing_key.go Outdated Show resolved Hide resolved

// GetKID returns the 'kid' field value to use in signing JWTs.
func (s *SMSSigningKey) GetKID() string {
return fmt.Sprintf("r%dv%d", s.RealmID, s.ID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to match realm.SMSSigningKeyID()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SMSSigningKeyID is the KMS key - this is the KID for public consumption

pkg/database/realm.go Show resolved Hide resolved
pkg/database/realm.go Outdated Show resolved Hide resolved
pkg/database/realm.go Outdated Show resolved Hide resolved
s.Active = active
}

func (s *SigningKey) Table() string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does passing in as Model not work? It might not, I've never tried.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will mess w/ that separate

Copy link
Member

@sethvargo sethvargo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mikehelmick, sethvargo

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [mikehelmick,sethvargo]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-robot google-oss-robot merged commit a0b72d0 into google:main Jan 21, 2021
@mikehelmick mikehelmick deleted the smsKeys branch January 21, 2021 19:50
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes Auto: added by CLA bot when all committers have signed a CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants