-
Notifications
You must be signed in to change notification settings - Fork 13
Add secret auth flow flag #323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
075c74b
Add fetch for tenant config and write context file
timothyF95 37851ef
Merge branch 'main' into add-context-file-fetch
timothyF95 a5ab4d0
Update based on new api changes
timothyF95 86f55d7
Merge branch 'main' into add-context-file-fetch
timothyF95 1caba32
lint
timothyF95 98a5b95
Merge branch 'main' into add-context-file-fetch
timothyF95 ee6fec2
Adjust for latest api changes
timothyF95 fec7d66
add support for api key
timothyF95 f3bb708
Clean up
timothyF95 e80c452
Merge branch 'main' into add-context-file-fetch
timothyF95 4acdad8
Extract orgID from claim
timothyF95 b9d403d
review feedback
timothyF95 023c3b4
tenant -> user context
timothyF95 05662dd
Merge branch 'main' into add-context-file-fetch
timothyF95 9d9804c
Merge branch 'add-context-file-fetch' into extract-orgid-from-claim
timothyF95 dc9e013
Merge branch 'main' into extract-orgid-from-claim
timothyF95 b3d22ab
Merge branch 'extract-orgid-from-claim' of ssh://github.com/smartcont…
timothyF95 2fa431a
Add secret auth flow flag
timothyF95 c8d5ec8
Merge branch 'main' into add-secret-auth-flow-flag
timothyF95 d510615
refactor tests
timothyF95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package common | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
| ) | ||
|
|
||
| const ( | ||
| SecretsAuthOwnerKeySigning = "owner-key-signing" | ||
| SecretsAuthBrowser = "browser" | ||
| ) | ||
|
|
||
| // ValidateSecretsAuthFlow checks that the chosen auth flow is valid and | ||
| // allowed in the current environment. Browser flow is blocked in production. | ||
| func ValidateSecretsAuthFlow(flow, envName string) error { | ||
| switch flow { | ||
| case SecretsAuthOwnerKeySigning: | ||
| return nil | ||
| case SecretsAuthBrowser: | ||
| if strings.EqualFold(envName, "PRODUCTION") || envName == "" { | ||
| return fmt.Errorf("browser auth flow is not yet available in production; use owner-key-signing") | ||
| } | ||
| return nil | ||
| default: | ||
| return fmt.Errorf("unknown --secrets-auth value %q; expected %q or %q", flow, SecretsAuthOwnerKeySigning, SecretsAuthBrowser) | ||
| } | ||
| } | ||
|
|
||
| // IsBrowserFlow returns true when the browser (JWT) auth flow is selected. | ||
| func IsBrowserFlow(flow string) bool { | ||
| return flow == SecretsAuthBrowser | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package common | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestValidateSecretsAuthFlow(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| flow string | ||
| env string | ||
| wantErr bool | ||
| errMsg string | ||
| }{ | ||
| {"owner-key-signing in production", SecretsAuthOwnerKeySigning, "PRODUCTION", false, ""}, | ||
| {"owner-key-signing in staging", SecretsAuthOwnerKeySigning, "STAGING", false, ""}, | ||
| {"owner-key-signing in dev", SecretsAuthOwnerKeySigning, "DEVELOPMENT", false, ""}, | ||
| {"owner-key-signing empty env defaults safe", SecretsAuthOwnerKeySigning, "", false, ""}, | ||
| {"browser in staging", SecretsAuthBrowser, "STAGING", false, ""}, | ||
| {"browser in dev", SecretsAuthBrowser, "DEVELOPMENT", false, ""}, | ||
| {"browser in production blocked", SecretsAuthBrowser, "PRODUCTION", true, "not yet available in production"}, | ||
| {"browser in production lowercase", SecretsAuthBrowser, "production", true, "not yet available in production"}, | ||
| {"browser empty env treated as production", SecretsAuthBrowser, "", true, "not yet available in production"}, | ||
| {"unknown value rejected", "magic", "STAGING", true, "unknown --secrets-auth value"}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| err := ValidateSecretsAuthFlow(tt.flow, tt.env) | ||
| if tt.wantErr { | ||
| require.Error(t, err) | ||
| if tt.errMsg != "" { | ||
| require.Contains(t, err.Error(), tt.errMsg) | ||
| } | ||
| } else { | ||
| require.NoError(t, err) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestIsBrowserFlow(t *testing.T) { | ||
| assert.False(t, IsBrowserFlow(SecretsAuthOwnerKeySigning), "owner-key-signing should not be browser flow") | ||
| assert.True(t, IsBrowserFlow(SecretsAuthBrowser), "browser should be browser flow") | ||
| assert.False(t, IsBrowserFlow("unknown"), "unknown should not be browser flow") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,14 @@ func New(ctx *runtime.Context) *cobra.Command { | |
| Use: "list", | ||
| Short: "Lists secret identifiers for the current owner address in the given namespace.", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| secretsAuth, err := cmd.Flags().GetString("secrets-auth") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if err := common.ValidateSecretsAuthFlow(secretsAuth, ctx.EnvironmentSet.EnvName); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| h, err := common.NewHandler(ctx, "") | ||
| if err != nil { | ||
| return err | ||
|
|
@@ -58,12 +66,7 @@ func New(ctx *runtime.Context) *cobra.Command { | |
| return fmt.Errorf("invalid --timeout: must be greater than 0 and less than %dh (%dd)", maxHours, maxDays) | ||
| } | ||
|
|
||
| return Execute( | ||
| h, | ||
| namespace, | ||
| duration, | ||
| ctx.Settings.Workflow.UserWorkflowSettings.WorkflowOwnerType, | ||
| ) | ||
| return Execute(h, namespace, duration, secretsAuth) | ||
| }, | ||
| } | ||
|
|
||
|
|
@@ -75,7 +78,7 @@ func New(ctx *runtime.Context) *cobra.Command { | |
| } | ||
|
|
||
| // Execute performs: build request → (MSIG step 1 bundle OR EOA allowlist+post) → parse. | ||
| func Execute(h *common.Handler, namespace string, duration time.Duration, ownerType string) error { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: ownerType was previously unused |
||
| func Execute(h *common.Handler, namespace string, duration time.Duration, secretsAuth string) error { | ||
| spinner := ui.NewSpinner() | ||
| spinner.Start("Verifying ownership...") | ||
| if err := h.EnsureOwnerLinkedOrFail(); err != nil { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ownerTypeparam wasn't used anywhere in secret commands?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it was pulled directly from the runtime context rather than passed as a param. I think this was leftover from a previous change