Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cmd/secrets/common/browser_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ const exchangeAuthCodeToTokenMutation = `mutation ExchangeAuthCodeToToken($reque
}`

// vaultPermissionForMethod returns the API permission name for the given vault operation.
// Names match the VaultPermission enum in platform GraphQL (createVaultAuthorizationUrl).
func vaultPermissionForMethod(method string) (string, error) {
switch method {
case vaulttypes.MethodSecretsCreate:
return "VAULT_PERMISSION_CREATE_SECRETS", nil
case vaulttypes.MethodSecretsUpdate:
return "VAULT_PERMISSION_UPDATE_SECRETS", nil
case vaulttypes.MethodSecretsDelete:
return "VAULT_PERMISSION_DELETE_SECRETS", nil
case vaulttypes.MethodSecretsList:
return "VAULT_PERMISSION_LIST_SECRETS", nil
default:
return "", fmt.Errorf("unsupported method: %s", method)
}
Expand Down Expand Up @@ -110,6 +115,16 @@ func (h *Handler) executeBrowserUpsert(ctx context.Context, inputs UpsertSecrets
return fmt.Errorf("unsupported method %q (expected %q or %q)", method, vaulttypes.MethodSecretsCreate, vaulttypes.MethodSecretsUpdate)
}

return h.ExecuteBrowserVaultAuthorization(ctx, method, digest)
}

// ExecuteBrowserVaultAuthorization completes platform OAuth for a vault JSON-RPC digest (create/update/delete/list).
// It does not POST to the gateway; the short-lived vault JWT is for future DON submission.
func (h *Handler) ExecuteBrowserVaultAuthorization(ctx context.Context, method string, digest [32]byte) error {
if h.Credentials.AuthType == credentials.AuthTypeApiKey {
return fmt.Errorf("this sign-in flow requires an interactive login; API keys are not supported")
}

perm, err := vaultPermissionForMethod(method)
if err != nil {
return err
Expand Down
10 changes: 9 additions & 1 deletion cmd/secrets/common/browser_flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ func TestVaultPermissionForMethod(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, "VAULT_PERMISSION_UPDATE_SECRETS", p)

_, err = vaultPermissionForMethod(vaulttypes.MethodSecretsDelete)
p, err = vaultPermissionForMethod(vaulttypes.MethodSecretsDelete)
require.NoError(t, err)
assert.Equal(t, "VAULT_PERMISSION_DELETE_SECRETS", p)

p, err = vaultPermissionForMethod(vaulttypes.MethodSecretsList)
require.NoError(t, err)
assert.Equal(t, "VAULT_PERMISSION_LIST_SECRETS", p)

_, err = vaultPermissionForMethod("vault/secrets/unknown")
require.Error(t, err)
}

Expand Down
6 changes: 6 additions & 0 deletions cmd/secrets/delete/delete.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package delete

import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -164,6 +165,11 @@ func Execute(h *common.Handler, inputs DeleteSecretsInputs, duration time.Durati
return fmt.Errorf("failed to calculate request digest: %w", err)
}

if common.IsBrowserFlow(secretsAuth) {
ui.Dim("Using your account to authorize vault access for this delete request...")
return h.ExecuteBrowserVaultAuthorization(context.Background(), vaulttypes.MethodSecretsDelete, digest)
}

gatewayPost := func() error {
respBody, status, err := h.Gw.Post(requestBody)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions cmd/secrets/list/list.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package list

import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -128,6 +129,11 @@ func Execute(h *common.Handler, namespace string, duration time.Duration, secret
return fmt.Errorf("failed to marshal JSON-RPC request: %w", err)
}

if common.IsBrowserFlow(secretsAuth) {
ui.Dim("Using your account to authorize vault access for this list request...")
return h.ExecuteBrowserVaultAuthorization(context.Background(), vaulttypes.MethodSecretsList, digest)
}

ownerAddr := ethcommon.HexToAddress(owner)

allowlisted, err := h.Wrc.IsRequestAllowlisted(ownerAddr, digest)
Expand Down
Loading