-
Notifications
You must be signed in to change notification settings - Fork 1
Add Snowflake credential issuance #144
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
Open
santhosh-c1
wants to merge
14
commits into
main
Choose a base branch
from
santhosh.kumar/credential-issuance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4b1ac28
Add Snowflake credential issuance
santhosh-c1 b368edc
Fix service user PAT role restriction
highb d1a71db
fix(pat): make issued tokens discoverable and stop orphaning them
highb f288029
refactor(pat): build the token statement once
highb 22b6058
test(pat): pin both issuance statement shapes
highb 22590a4
Merge pull request #145 from ConductorOne/c1-squire-dev/IGA-3962-role…
highb 6c05ee8
Merge branch 'main' into santhosh.kumar/credential-issuance
highb a1d824c
fix(pat): classify access-control denials on the async statement leg
highb ff1ec0c
fix(pat): match quoted role identifiers and run ALTER USER as USERADMIN
highb 74315c4
Merge pull request #148 from ConductorOne/c1-squire-dev/IGA-3962-stat…
highb 8f6276f
fix(pat): sample the expiry clock late and survive read-back denials
highb 2220f4d
Merge pull request #149 from ConductorOne/c1-squire-dev/IGA-3962-issu…
highb 3254fbd
fix(pat): surface issuance degradations at Warn and correct the docs …
highb 081a0c3
Merge pull request #150 from ConductorOne/c1-squire-dev/IGA-3962-degr…
highb 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
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 |
|---|---|---|
|
|
@@ -3,4 +3,5 @@ package connector | |
| const ( | ||
| profileKeyName = "name" | ||
| profileKeyComment = "comment" | ||
| profileKeyType = "type" | ||
| ) | ||
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,109 @@ | ||
| package connector | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/base64" | ||
| "fmt" | ||
| "strings" | ||
| "time" | ||
|
|
||
| v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2" | ||
| "github.com/conductorone/baton-sdk/pkg/annotations" | ||
| rs "github.com/conductorone/baton-sdk/pkg/types/resource" | ||
| "github.com/conductorone/baton-snowflake/pkg/snowflake" | ||
| "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| type programmaticAccessTokenBuilder struct { | ||
| client *snowflake.Client | ||
| } | ||
|
|
||
| func newProgrammaticAccessTokenBuilder(client *snowflake.Client) *programmaticAccessTokenBuilder { | ||
| return &programmaticAccessTokenBuilder{client: client} | ||
| } | ||
|
|
||
| func (o *programmaticAccessTokenBuilder) ResourceType(context.Context) *v2.ResourceType { | ||
| return programmaticAccessTokenResourceType | ||
| } | ||
|
|
||
| func (o *programmaticAccessTokenBuilder) List(ctx context.Context, parentID *v2.ResourceId, _ rs.SyncOpAttrs) ([]*v2.Resource, *rs.SyncOpResults, error) { | ||
| if parentID == nil || parentID.GetResourceType() != userResourceType.Id { | ||
| return nil, nil, nil | ||
| } | ||
|
c1-squire-dev[bot] marked this conversation as resolved.
|
||
| tokens, err := o.client.ListProgrammaticAccessTokens(ctx, parentID.GetResource()) | ||
| if err != nil { | ||
| // SHOW USER PROGRAMMATIC ACCESS TOKENS needs ownership or MONITOR on the target | ||
| // user. Without it Snowflake answers 422/003001, which means "nothing visible | ||
| // here" rather than a failure - one unprivileged user must not abort the sync. | ||
| if snowflake.IsInsufficientPrivileges(err) { | ||
| ctxzap.Extract(ctx).Debug("skipping programmatic access tokens: insufficient privileges", | ||
| zap.String("username", parentID.GetResource())) | ||
| return nil, &rs.SyncOpResults{}, nil | ||
| } | ||
| return nil, nil, fmt.Errorf("baton-snowflake: list programmatic access tokens: %w", err) | ||
| } | ||
| resources := make([]*v2.Resource, 0, len(tokens)) | ||
| for _, token := range tokens { | ||
| resource, err := newProgrammaticAccessTokenResource(parentID, token.Name, token.ExpiresAt) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
| resources = append(resources, resource) | ||
| } | ||
| return resources, nil, nil | ||
| } | ||
|
|
||
| func (o *programmaticAccessTokenBuilder) Entitlements(context.Context, *v2.Resource, rs.SyncOpAttrs) ([]*v2.Entitlement, *rs.SyncOpResults, error) { | ||
| return nil, nil, nil | ||
| } | ||
|
|
||
| func (o *programmaticAccessTokenBuilder) Grants(context.Context, *v2.Resource, rs.SyncOpAttrs) ([]*v2.Grant, *rs.SyncOpResults, error) { | ||
| return nil, nil, nil | ||
| } | ||
|
|
||
| func (o *programmaticAccessTokenBuilder) Delete(ctx context.Context, resourceID *v2.ResourceId, _ *v2.ResourceId) (annotations.Annotations, error) { | ||
| userName, tokenName, err := parseProgrammaticAccessTokenID(resourceID.GetResource()) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if err := o.client.RemoveProgrammaticAccessToken(ctx, userName, tokenName); err != nil { | ||
| return nil, fmt.Errorf("baton-snowflake: remove programmatic access token: %w", err) | ||
| } | ||
| return nil, nil | ||
| } | ||
|
|
||
| func newProgrammaticAccessTokenResource(identityID *v2.ResourceId, tokenName string, expiresAt time.Time) (*v2.Resource, error) { | ||
| return rs.NewSecretResource( | ||
| tokenName, | ||
| programmaticAccessTokenResourceType, | ||
| programmaticAccessTokenID(identityID.Resource, tokenName), | ||
| []rs.SecretTraitOption{ | ||
| rs.WithSecretCreatedByID(identityID), | ||
| rs.WithSecretIdentityID(identityID), | ||
| rs.WithSecretExpiresAt(expiresAt), | ||
| rs.WithSecretType(v2.SecretTrait_CREDENTIAL_TYPE_STATIC_SECRET), | ||
| rs.WithSecretDetail("snowflake.programmatic_access_token"), | ||
| }, | ||
| rs.WithParentResourceID(identityID), | ||
| ) | ||
| } | ||
|
|
||
| func programmaticAccessTokenID(userName, tokenName string) string { | ||
| return base64.RawURLEncoding.EncodeToString([]byte(userName)) + "." + tokenName | ||
| } | ||
|
|
||
| func parseProgrammaticAccessTokenID(resourceID string) (string, string, error) { | ||
| parts := strings.SplitN(resourceID, ".", 2) | ||
| if len(parts) != 2 || parts[0] == "" || parts[1] == "" { | ||
| return "", "", fmt.Errorf("baton-snowflake: invalid programmatic access token resource id") | ||
| } | ||
| userName, err := base64.RawURLEncoding.DecodeString(parts[0]) | ||
| if err != nil || len(userName) == 0 { | ||
| return "", "", fmt.Errorf("baton-snowflake: invalid programmatic access token user id") | ||
| } | ||
| if strings.ContainsAny(parts[1], "\";") { | ||
| return "", "", fmt.Errorf("baton-snowflake: invalid programmatic access token name") | ||
| } | ||
| return string(userName), parts[1], nil | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.