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 committed Dec 9, 2024
1 parent 03077a4 commit 8b1ff51
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 @@ -560,6 +560,10 @@ const (
// KindStaticHostUser is a host user to be created on matching SSH nodes.
KindStaticHostUser = "static_host_user"

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

// KindWorkloadIdentity is the WorkloadIdentity resource.
KindWorkloadIdentity = "workload_identity"

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.KindNotification, RW()),
types.NewRule(types.KindStaticHostUser, RW()),
types.NewRule(types.KindUserTask, 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 @@ -74,6 +74,7 @@ export const allAccessAcl: Acl = {
accessGraph: fullAccess,
bots: fullAccess,
accessMonitoringRule: 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 @@ -73,6 +73,8 @@ export function makeAcl(json): Acl {
const bots = json.bots || defaultAccess;
const accessMonitoringRule = json.accessMonitoringRule || defaultAccess;

const contacts = json.contact || defaultAccess;

return {
accessList,
authConnectors,
Expand Down Expand Up @@ -109,6 +111,7 @@ export function makeAcl(json): Acl {
accessGraph,
bots,
accessMonitoringRule,
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 @@ -105,6 +105,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 @@ -271,6 +271,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 @@ -247,4 +247,8 @@ export default class StoreUserContext extends Store<UserContext> {
getBotsAccess() {
return this.state.acl.bots;
}

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

0 comments on commit 8b1ff51

Please sign in to comment.