-
Notifications
You must be signed in to change notification settings - Fork 99
project: Identity and Access Management #866
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
6 commits
Select commit
Hold shift + click to select a range
94cb953
Support for Entities and IAM endpoints (#754)
jriddle-linode f6684f4
Merge pull request #856 from linode/main
zliang-akamai 52611e3
Merge branch 'main' into proj/iam
jriddle-linode 1d31b10
IO Ready and new IAM Endpoints (#864)
jriddle-linode 0370427
Merge branch 'main' into proj/iam
jriddle-linode 1051e57
pr feedback
jriddle-linode 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package linodego | ||
|
|
||
| import "context" | ||
|
|
||
| // LinodeEntity is anything in Linode with IAM Permissions | ||
| type LinodeEntity struct { | ||
| ID int `json:"id"` | ||
| Label string `json:"label"` | ||
| Type string `json:"type"` | ||
| } | ||
|
|
||
| // ListEntities returns a paginated list of all entities | ||
| func (c *Client) ListEntities(ctx context.Context, opts *ListOptions) ([]LinodeEntity, error) { | ||
| return getPaginatedResults[LinodeEntity](ctx, c, "entities", opts) | ||
| } | ||
|
|
||
| // GetEntityRoles returns a list of roles for the entity and user | ||
| func (c *Client) GetEntityRoles(ctx context.Context, username string, entityType string, entityID int) ([]string, error) { | ||
| perms, err := doGETRequest[[]string](ctx, c, | ||
| formatAPIPath("iam/users/%s/permissions/%s/%d", username, entityType, entityID)) | ||
| if err != nil || perms == nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return (*perms), err | ||
| } |
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,80 @@ | ||
| package linodego | ||
|
|
||
| import "context" | ||
|
|
||
| // UserRolePermissions are the account and entity permissions for the User | ||
| type UserRolePermissions struct { | ||
| AccountAccess []string `json:"account_access"` | ||
| EntityAccess []UserAccess `json:"entity_access"` | ||
| } | ||
|
|
||
| // GetUpdateOptions converts UserRolePermissions for use in UpdateUserRolePermissions | ||
| func (p *UserRolePermissions) GetUpdateOptions() UserRolePermissionsUpdateOptions { | ||
| return UserRolePermissionsUpdateOptions{ | ||
| AccountAccess: p.AccountAccess, | ||
| EntityAccess: p.EntityAccess, | ||
| } | ||
| } | ||
|
|
||
| // UserRolePermissionsUpdateOptions are fields accepted by UpdateUserRolePermissions | ||
| type UserRolePermissionsUpdateOptions struct { | ||
| AccountAccess []string `json:"account_access"` | ||
| EntityAccess []UserAccess `json:"entity_access"` | ||
| } | ||
|
|
||
| // UserAccess is the breakdown of entities Roles | ||
| type UserAccess struct { | ||
| ID int `json:"id"` | ||
| Type string `json:"type"` | ||
| Roles []string `json:"roles"` | ||
| } | ||
|
|
||
| // AccountRolePermissions are the account and entity roles for the Account | ||
| type AccountRolePermissions struct { | ||
| AccountAccess []AccountAccess `json:"account_access"` | ||
| EntityAccess []AccountAccess `json:"entity_access"` | ||
| } | ||
|
|
||
| // AccountAccess is the Roles for each Type for the Account | ||
| type AccountAccess struct { | ||
| Type string `json:"type"` | ||
| Roles []Role `json:"roles"` | ||
| } | ||
|
|
||
| // Role is the IAM Role and its Permissions | ||
| type Role struct { | ||
| Name string `json:"name"` | ||
| Description string `json:"description"` | ||
| Permissions []string `json:"permissions"` | ||
| } | ||
|
|
||
| // GetUserRolePermissions returns any role permissions for username | ||
| func (c *Client) GetUserRolePermissions(ctx context.Context, username string) (*UserRolePermissions, error) { | ||
| return doGETRequest[UserRolePermissions](ctx, c, | ||
| formatAPIPath("iam/users/%s/role-permissions", username), | ||
| ) | ||
| } | ||
|
|
||
| // UpdateUserRolePermissions updates any role permissions for username | ||
| func (c *Client) UpdateUserRolePermissions(ctx context.Context, username string, opts UserRolePermissionsUpdateOptions) (*UserRolePermissions, error) { | ||
| return doPUTRequest[UserRolePermissions](ctx, c, | ||
| formatAPIPath("iam/users/%s/role-permissions", username), | ||
| opts, | ||
| ) | ||
| } | ||
|
|
||
| // GetAccountRolePermissions returns the role permissions for this Account | ||
| func (c *Client) GetAccountRolePermissions(ctx context.Context) (*AccountRolePermissions, error) { | ||
| return doGETRequest[AccountRolePermissions](ctx, c, "iam/role-permissions") | ||
| } | ||
|
|
||
| // GetUserAccountPermissions returns the account permissions for username | ||
| func (c *Client) GetUserAccountPermissions(ctx context.Context, username string) ([]string, error) { | ||
| perms, err := doGETRequest[[]string](ctx, c, | ||
| formatAPIPath("iam/users/%s/permissions/account", username)) | ||
| if err != nil || perms == nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return (*perms), err | ||
| } | ||
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,41 @@ | ||
| package unit | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/linode/linodego" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestEntities_List(t *testing.T) { | ||
| fixtureData, err := fixtures.GetFixture("entities_list") | ||
| assert.NoError(t, err) | ||
|
|
||
| var base ClientBaseCase | ||
| base.SetUp(t) | ||
| defer base.TearDown(t) | ||
|
|
||
| base.MockGet(formatMockAPIPath("entities"), fixtureData) | ||
|
|
||
| entities, err := base.Client.ListEntities(context.Background(), &linodego.ListOptions{}) | ||
| assert.NoError(t, err) | ||
|
|
||
| assert.Equal(t, 7, entities[0].ID) | ||
| } | ||
|
|
||
| func TestEntitiesPermissions_Get(t *testing.T) { | ||
| fixtureData, err := fixtures.GetFixture("entities_permissions") | ||
| assert.NoError(t, err) | ||
|
|
||
| var base ClientBaseCase | ||
| base.SetUp(t) | ||
| defer base.TearDown(t) | ||
|
|
||
| base.MockGet(formatMockAPIPath("iam/users/Linode/permissions/linode/123"), fixtureData) | ||
|
|
||
| perms, err := base.Client.GetEntityRoles(context.Background(), "Linode", "linode", 123) | ||
| assert.NoError(t, err) | ||
|
|
||
| assert.Equal(t, "rebuild_linode", perms[1]) | ||
| } |
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,27 @@ | ||
| { | ||
| "data": [ | ||
| { | ||
| "id": 7, | ||
| "label": "linode7", | ||
| "type": "linode" | ||
| }, | ||
| { | ||
| "id": 10, | ||
| "label": "linode10", | ||
| "type": "linode" | ||
| }, | ||
| { | ||
| "id": 1, | ||
| "label": "no_devices", | ||
| "type": "firewall" | ||
| }, | ||
| { | ||
| "id": 2, | ||
| "label": "active_with_nodebalancer", | ||
| "type": "firewall" | ||
| } | ||
| ], | ||
| "page": 1, | ||
| "pages": 1, | ||
| "results": 4 | ||
| } |
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,5 @@ | ||
| [ | ||
| "generate_linode_lish_token_remote", | ||
| "rebuild_linode", | ||
| "shutdown_linode" | ||
| ] |
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,81 @@ | ||
| { | ||
| "account_access": [ | ||
| { | ||
| "type": "account", | ||
| "roles": [ | ||
| { | ||
| "name": "account_admin", | ||
| "description": "Access to perform any supported action on all entities of the account", | ||
| "permissions": [ | ||
| "create_linode", | ||
| "update_linode", | ||
| "update_firewall" | ||
| ] | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "type": "linode", | ||
| "roles": [ | ||
| { | ||
| "name": "account_linode_admin", | ||
| "description": "Access to perform any supported action on all linode instances of the account", | ||
| "permissions": [ | ||
| "create_linode", | ||
| "update_linode", | ||
| "delete_linode" | ||
| ] | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "type": "firewall", | ||
| "roles": [ | ||
| { | ||
| "name": "firewall_creator", | ||
| "description": "Access to create a firewall instance", | ||
| "permissions": [ | ||
| "update_linode", | ||
| "view_linode" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "entity_access": [ | ||
| { | ||
| "type": "linode", | ||
| "roles": [ | ||
| { | ||
| "name": "linode_contributor", | ||
| "description": "Access to update a linode instance", | ||
| "permissions": [ | ||
| "update_linode", | ||
| "view_linode" | ||
| ] | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "type": "firewall", | ||
| "roles": [ | ||
| { | ||
| "name": "firewall_viewer", | ||
| "description": "Access to view a firewall instance", | ||
| "permissions": [ | ||
| "update_linode", | ||
| "view_linode" | ||
| ] | ||
| }, | ||
| { | ||
| "name": "firewall_admin", | ||
| "description": "Access to perform any supported action on a firewall instance", | ||
| "permissions": [ | ||
| "update_linode", | ||
| "view_linode" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
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,5 @@ | ||
| [ | ||
| "list_events", | ||
| "view_account_settings", | ||
| "cancel_account" | ||
| ] |
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,23 @@ | ||
| { | ||
| "account_access": [ | ||
| "account_linode_admin", | ||
| "linode_creator", | ||
| "firewall_creator" | ||
| ], | ||
| "entity_access": [ | ||
| { | ||
| "id": 1, | ||
| "type": "linode", | ||
| "roles": [ | ||
| "linode_contributor" | ||
| ] | ||
| }, | ||
| { | ||
| "id": 1, | ||
| "type": "firewall", | ||
| "roles": [ | ||
| "firewall_admin" | ||
| ] | ||
| } | ||
| ] | ||
| } |
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,24 @@ | ||
| { | ||
| "account_access": [ | ||
| "account_linode_admin", | ||
| "linode_creator", | ||
| "firewall_creator", | ||
| "test_admin" | ||
| ], | ||
| "entity_access": [ | ||
| { | ||
| "id": 1, | ||
| "type": "linode", | ||
| "roles": [ | ||
| "linode_contributor" | ||
| ] | ||
| }, | ||
| { | ||
| "id": 1, | ||
| "type": "firewall", | ||
| "roles": [ | ||
| "firewall_admin" | ||
| ] | ||
| } | ||
| ] | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.