Skip to content

Commit

Permalink
Add Contacts RBAC (#48885)
Browse files Browse the repository at this point in the history
* Add Contact resource; include it in default editor permissions and web ACL

* Add contacts to ACL test

* Improve godocs

Co-authored-by: Zac Bergquist <[email protected]>

* Add `contact` to the web user context

---------

Co-authored-by: Zac Bergquist <[email protected]>
  • Loading branch information
mcbattirola and zmb3 authored Dec 3, 2024
1 parent 911f3e3 commit 4f62286
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/types/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,10 @@ const (
// pair that can be requested by a Teleport User.
KindIdentityCenterAccountAssignment = "aws_ic_account_assignment"

// KindContact is a resource that holds contact information
// for Teleport Enterprise customers.
KindContact = "contact"

// KindGitServer represents a Git server that can proxy git commands.
KindGitServer = "git_server"
// SubKindGitHub specifies the GitHub subkind of a Git server.
Expand Down
1 change: 1 addition & 0 deletions lib/services/presets.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func NewPresetEditorRole() types.Role {
types.NewRule(types.KindStaticHostUser, RW()),
types.NewRule(types.KindUserTask, RW()),
types.NewRule(types.KindIdentityCenter, RW()),
types.NewRule(types.KindContact, RW()),
},
},
},
Expand Down
5 changes: 5 additions & 0 deletions lib/services/useracl.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ type UserACL struct {
AccessGraphSettings ResourceAccess `json:"accessGraphSettings"`
// ReviewRequests defines the ability to review requests
ReviewRequests bool `json:"reviewRequests"`
// Contact defines the ability to manage contacts
Contact ResourceAccess `json:"contact"`
}

func hasAccess(roleSet RoleSet, ctx *Context, kind string, verbs ...string) bool {
Expand Down Expand Up @@ -216,6 +218,8 @@ func NewUserACL(user types.User, userRoles RoleSet, features proto.Features, des
securityReports = newAccess(userRoles, ctx, types.KindSecurityReport)
}

contact := newAccess(userRoles, ctx, types.KindContact)

return UserACL{
AccessRequests: requestAccess,
AppServers: appServerAccess,
Expand Down Expand Up @@ -257,5 +261,6 @@ func NewUserACL(user types.User, userRoles RoleSet, features proto.Features, des
AccessMonitoringRule: accessMonitoringRules,
CrownJewel: crownJewelAccess,
AccessGraphSettings: accessGraphSettings,
Contact: contact,
}
}
5 changes: 5 additions & 0 deletions lib/services/useracl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func TestNewUserACL(t *testing.T) {
Resources: []string{types.KindIntegration},
Verbs: append(RW(), types.VerbUse),
},
{
Resources: []string{types.KindContact},
Verbs: RW(),
},
})

// not setting the rule, or explicitly denying, both denies Access
Expand Down Expand Up @@ -104,6 +108,7 @@ func TestNewUserACL(t *testing.T) {
require.True(t, userContext.DesktopSessionRecording)
require.Empty(t, cmp.Diff(userContext.License, denied))
require.Empty(t, cmp.Diff(userContext.Download, denied))
require.Empty(t, cmp.Diff(userContext.Contact, allowedRW))

// test enabling of the 'Use' verb
require.Empty(t, cmp.Diff(userContext.Integrations, ResourceAccess{true, true, true, true, true, true}))
Expand Down
1 change: 1 addition & 0 deletions web/packages/teleport/src/mocks/contexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const allAccessAcl: Acl = {
bots: fullAccess,
accessMonitoringRule: fullAccess,
discoverConfigs: fullAccess,
contacts: fullAccess,
};

export function getAcl(cfg?: { noAccess: boolean }) {
Expand Down
3 changes: 3 additions & 0 deletions web/packages/teleport/src/services/user/makeAcl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export function makeAcl(json): Acl {

const discoverConfigs = json.discoverConfigs || defaultAccess;

const contacts = json.contact || defaultAccess;

return {
accessList,
authConnectors,
Expand Down Expand Up @@ -112,6 +114,7 @@ export function makeAcl(json): Acl {
bots,
accessMonitoringRule,
discoverConfigs,
contacts,
};
}

Expand Down
1 change: 1 addition & 0 deletions web/packages/teleport/src/services/user/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export interface Acl {
accessGraph: Access;
bots: Access;
accessMonitoringRule: Access;
contacts: Access;
}

// AllTraits represent all the traits defined for a user.
Expand Down
7 changes: 7 additions & 0 deletions web/packages/teleport/src/services/user/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ test('undefined values in context response gives proper default values', async (
create: false,
remove: false,
},
contacts: {
list: false,
read: false,
edit: false,
create: false,
remove: false,
},
clipboardSharingEnabled: true,
desktopSessionRecordingEnabled: true,
directorySharingEnabled: true,
Expand Down
4 changes: 4 additions & 0 deletions web/packages/teleport/src/stores/storeUserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,8 @@ export default class StoreUserContext extends Store<UserContext> {
getBotsAccess() {
return this.state.acl.bots;
}

getContactsAccess() {
return this.state.acl.contacts;
}
}

0 comments on commit 4f62286

Please sign in to comment.