- 
                Notifications
    
You must be signed in to change notification settings  - Fork 30
 
feat: add 'groups' namespace for managing RBAC groups #343
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 3 commits
      Commits
    
    
            Show all changes
          
          
            5 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      25e9687
              
                feat: add 'groups' namespace for managing OIDC groups
              
              
                bevzzz 4273a30
              
                feat: add permissions for OIDC groups
              
              
                bevzzz 036efd7
              
                test: await cleanup
              
              
                bevzzz 194c42e
              
                chore: add missing param docstring
              
              
                bevzzz 66d2915
              
                feat: quote user IDs when they're part of the URL
              
              
                bevzzz 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,66 @@ | ||
| import ConnectionREST from '../connection/http.js'; | ||
| import { Role } from '../roles/types.js'; | ||
| import { Map } from '../roles/util.js'; | ||
| 
     | 
||
| import { Role as WeaviateRole } from '../openapi/types.js'; | ||
| 
     | 
||
| export interface Groups { | ||
| /** Manage roles of OIDC user groups. */ | ||
| oidc: GroupsOIDC; | ||
| } | ||
| 
     | 
||
| export interface GroupsOIDC { | ||
| /** | ||
| * Get the roles assigned to a group specific to the configured OIDC's dynamic auth functionality. | ||
| * | ||
| * @param {string} groupID The group ID to get the roles for. | ||
| * @returns {Promise<Record<string, Role>>} A map of roles assigned to the group. | ||
| */ | ||
| getAssignedRoles(groupID: string, includePermissions?: boolean): Promise<Record<string, Role>>; | ||
| 
     | 
||
| /** | ||
| * Assign roles to a group specific to the configured OIDC's dynamic auth functionality. | ||
| * | ||
| * @param {string} groupID The group ID to get the roles for. | ||
| * @param {string | string[]} roles The names of the roles to assign to the group. | ||
| */ | ||
| assignRoles(groupID: string, roles: string | string[]): Promise<void>; | ||
| /** | ||
| * Revoke roles from a group specific to the configured OIDC's dynamic auth functionality. | ||
| * | ||
| * @param {string} groupID The group ID to get the roles for. | ||
| * @param {string | string[]} roles The names of the roles to revoke from the group. | ||
| */ | ||
| revokeRoles(groupID: string, roles: string | string[]): Promise<void>; | ||
| /** | ||
| * Get the known group names specific to the configured OIDC's dynamic auth functionality. | ||
| * | ||
| * @returns {Promise<string[]>} A list of known group names. | ||
| */ | ||
| getKnownGroupNames(): Promise<string[]>; | ||
| } | ||
| 
     | 
||
| export const groups = (connection: ConnectionREST): Groups => ({ | ||
| oidc: { | ||
| getAssignedRoles: (groupID, includePermissions) => | ||
| connection | ||
| .get<WeaviateRole[]>( | ||
| `/authz/groups/${encodeURIComponent(groupID)}/roles/oidc${ | ||
| includePermissions ? '?includeFullRoles=true' : '' | ||
| }` | ||
| ) | ||
| .then(Map.roles), | ||
| assignRoles: (groupID: string, roles: string | string[]): Promise<void> => | ||
| connection.postEmpty<any>(`/authz/groups/${encodeURIComponent(groupID)}/assign`, { | ||
| roles: Array.isArray(roles) ? roles : [roles], | ||
| groupType: 'oidc', | ||
| }), | ||
| revokeRoles: (groupID: string, roles: string | string[]): Promise<void> => | ||
| connection.postEmpty<any>(`/authz/groups/${encodeURIComponent(groupID)}/revoke`, { | ||
| roles: Array.isArray(roles) ? roles : [roles], | ||
| groupType: 'oidc', | ||
| }), | ||
| getKnownGroupNames: (): Promise<string[]> => connection.get(`/authz/groups/oidc`), | ||
| }, | ||
| }); | ||
| export default groups; | ||
  
    
      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,75 @@ | ||
| import weaviate, { ApiKey, GroupAssignment } from '..'; | ||
| import { requireAtLeast } from '../../test/version.js'; | ||
| 
     | 
||
| requireAtLeast(1, 32, 5).describe('Integration testing of the OIDC groups', () => { | ||
| const makeClient = (key: string = 'admin-key') => | ||
| weaviate.connectToLocal({ | ||
| port: 8091, | ||
| grpcPort: 50062, | ||
| authCredentials: new ApiKey(key), | ||
| }); | ||
| 
     | 
||
| it('should assign / get / revoke group roles', async () => { | ||
| const client = await makeClient(); | ||
| const groupID = './assign-group'; | ||
| const roles = ['viewer', 'admin']; | ||
| 
     | 
||
| await client.groups.oidc.revokeRoles(groupID, roles); | ||
| await expect(client.groups.oidc.getAssignedRoles(groupID)).resolves.toEqual({}); | ||
| 
     | 
||
| await client.groups.oidc.assignRoles(groupID, roles); | ||
| const assignedRoles = await client.groups.oidc.getAssignedRoles(groupID, true); | ||
| expect(Object.keys(assignedRoles)).toEqual(expect.arrayContaining(roles)); | ||
| 
     | 
||
| await client.groups.oidc.revokeRoles(groupID, roles); | ||
| await expect(client.groups.oidc.getAssignedRoles(groupID)).resolves.toEqual({}); | ||
| }); | ||
| 
     | 
||
| it('should get all known role groups', async () => { | ||
| const client = await makeClient(); | ||
| const group1 = './group-1'; | ||
| const group2 = './group-2'; | ||
| 
     | 
||
| await client.groups.oidc.assignRoles(group1, 'viewer'); | ||
| await client.groups.oidc.assignRoles(group2, 'viewer'); | ||
| 
     | 
||
| await expect(client.groups.oidc.getKnownGroupNames()).resolves.toEqual( | ||
| expect.arrayContaining([group1, group2]) | ||
| ); | ||
| 
     | 
||
| await client.groups.oidc.revokeRoles(group1, 'viewer'); | ||
| await client.groups.oidc.revokeRoles(group2, 'viewer'); | ||
| 
     | 
||
| await expect(client.groups.oidc.getKnownGroupNames()).resolves.toHaveLength(0); | ||
| }); | ||
| 
     | 
||
| it('should get group assignments', async () => { | ||
| const client = await makeClient(); | ||
| const roleName = 'test_group_assignements_role'; | ||
| await client.roles.delete(roleName).catch((e) => {}); | ||
| await client.roles.create(roleName, []).catch((e) => {}); | ||
| 
     | 
||
| await expect(client.roles.getGroupAssignments(roleName)).resolves.toHaveLength(0); | ||
| 
     | 
||
| await client.groups.oidc.assignRoles('./group-1', roleName); | ||
| await client.groups.oidc.assignRoles('./group-2', roleName); | ||
| await expect(client.roles.getGroupAssignments(roleName)).resolves.toEqual( | ||
| expect.arrayContaining<GroupAssignment>([ | ||
| { groupID: './group-1', groupType: 'oidc' }, | ||
| { groupID: './group-2', groupType: 'oidc' }, | ||
| ]) | ||
| ); | ||
| 
     | 
||
| await client.groups.oidc.revokeRoles('./group-1', roleName); | ||
| await client.groups.oidc.revokeRoles('./group-2', roleName); | ||
| await expect(client.roles.getGroupAssignments(roleName)).resolves.toHaveLength(0); | ||
| }); | ||
| 
     | 
||
| it('cleanup', async () => { | ||
| await makeClient().then((c) => { | ||
| c.groups.oidc.revokeRoles('./assign-group', ['viewer', 'admin']).catch((e) => {}); | ||
| c.groups.oidc.revokeRoles('./group-1', 'viewer').catch((e) => {}); | ||
| c.groups.oidc.revokeRoles('./group-2', 'viewer').catch((e) => {}); | ||
| }); | ||
| }); | ||
| }); | 
  
    
      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
    
  
  
    
              
  
    
      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.
        
    
  
      
      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.