Skip to content

Conversation

@rshade
Copy link
Contributor

@rshade rshade commented Oct 7, 2025

Add four new data sources (invoke functions) to enable querying and auditing organization permissions in Pulumi Cloud:

  • getTeams: List all teams in an organization with their members, stack permissions, and environment permissions
  • getTeamsForUser: Find which teams a specific user belongs to by searching their username or GitHub login
  • getStacks: List all stacks accessible by the authenticated user with pagination support
  • getStackPermissions: Query detailed team and user permissions for a specific stack

Implementation Details

API Client Methods

  • Added ListUserStacks() to query accessible stacks via /api/user/stacks
  • Added ListStackTeamPermissions() to query team access via /api/stacks/{org}/{project}/{stack}/teams
  • Added ListStackCollaborators() to query user access via /api/stacks/{org}/{project}/{stack}/collaborators
  • Enhanced existing UserInfo type to include AvatarUrl and Email fields

Provider Changes

  • Implemented four invoke function handlers in provider.go
  • Added comprehensive property conversion helpers
  • Added schema definitions for all four invoke functions with detailed input/output specifications

SDK Generation

  • Generated SDKs for all supported languages (TypeScript, Python, Go, .NET, Java)
  • All new invoke functions are available across all language SDKs

Documentation

  • Added comprehensive YAML example (yaml-permissions-query) demonstrating all four invoke functions
  • Created detailed README with usage examples, use cases, and conversion instructions
  • Updated CHANGELOG.md with feature descriptions

Testing

  • ✅ Added integration test TestYamlPermissionsQueryExample in examples/examples_yaml_test.go - PASSING
  • ✅ All linting passes with zero issues
  • ✅ Provider builds successfully
  • ✅ All SDKs generate without errors
  • ✅ Integration test validates both getTeams and getStacks data sources successfully query live data

Use Cases

These data sources enable several important scenarios:

  1. Audit Organization Access: Get complete view of teams, members, and resource access
  2. User Access Review: Quickly determine what teams and resources a user has access to
  3. Stack Discovery: Find all accessible stacks across the organization
  4. Permission Analysis: Understand exactly who has access to sensitive stacks

Fixes #509

@github-actions
Copy link

github-actions bot commented Oct 7, 2025

Does the PR have any schema changes?

Looking good! No breaking changes found.

New functions:

  • index.getStackCollaborators
  • index.getStackTeamPermissions
  • index.getStacks
  • index.getTeams
  • index.getTeamsForUser

Maintainer note: consult the runbook for dealing with any breaking changes.

@rshade rshade requested a review from Copilot October 8, 2025 13:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds four new data sources (invoke functions) to enable querying and auditing organization permissions in Pulumi Cloud for better access management and compliance workflows.

  • Adds comprehensive permission auditing capabilities through four new invoke functions
  • Enhances API client with methods for querying stacks and permissions
  • Generates complete SDK coverage across all supported languages

Reviewed Changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated no comments.

Show a summary per file
File Description
sdk/python/pulumi_pulumiservice/*.py Generated Python SDK bindings for the four new invoke functions
sdk/nodejs/*.ts Generated TypeScript SDK bindings and module exports
sdk/go/pulumiservice/*.go Generated Go SDK bindings with proper output types
sdk/dotnet/*.cs Generated .NET SDK bindings with immutable collections
provider/pkg/pulumiapi/stack.go API client methods for stack querying and permission retrieval
provider/pkg/pulumiapi/approvals.go Enhanced UserInfo type with avatar and email fields
provider/pkg/provider/provider.go Implementation of four invoke function handlers
provider/cmd/pulumi-resource-pulumiservice/schema.json Schema definitions for all new invoke functions
examples/yaml-permissions-query/* Comprehensive example demonstrating usage
examples/examples_yaml_test.go Integration test for the new functionality
CHANGELOG.md Documentation of the new features

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@rshade rshade requested a review from a team October 8, 2025 13:38
@rshade rshade enabled auto-merge (squash) October 14, 2025 20:39
@rshade
Copy link
Contributor Author

rshade commented Oct 14, 2025

@arunkumar611 This should fix your ticket.

Copy link
Member

@fnune fnune left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would normally approve, but you have enabled auto-merge before getting reviews, so I'm leaving a comments-only review.

I see a lack of testing, I think the integration example examples/yaml-permissions-query/Pulumi.yaml does not exercise the whole API surface.

I also have a minor product concern in that the *Permissions method is an amalgamation of two API calls that may not exactly mean the same as "permissions". I would rather see a cleaner 1-to-1 mapping of the API behavior to the provider functionality.

Comment on lines 698 to 699
// invokeFunctionGetStackPermissions implements the getStackPermissions function
func (k *pulumiserviceProvider) invokeFunctionGetStackPermissions(ctx context.Context, req *pulumirpc.InvokeRequest) (*pulumirpc.InvokeResponse, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this one need to go into one? It performs two API calls that do something slightly different, maybe it could map more directly to how our API looks?

Also, I'm not sure how this works, but does fetching collaborators return users that have access to the stack on their own, or do they have access by virtue of being part of a team? In the latter case, is it relevant to know by which team membership they have access?

Comment on lines 9 to 37
variables:
# Query all teams in the organization
# Returns: teams[] with kind, name, displayName, description, members[], stacks[], environments[]
allTeams:
fn::invoke:
function: pulumiservice:index:getTeams
arguments:
organizationName: ${organizationName}
return: teams

# Query all accessible stacks
# Returns: stacks[] with id, orgName, projectName, stackName, lastUpdate, resourceCount
allStacks:
fn::invoke:
function: pulumiservice:index:getStacks
arguments: {}
return: stacks
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we exercise the remainder of the methods as well?

Add four new data sources (invoke functions) to enable querying and auditing
organization permissions in Pulumi Cloud:

- `getTeams`: List all teams in an organization with their members, stack
  permissions, and environment permissions
- `getTeamsForUser`: Find which teams a specific user belongs to by searching
  their username or GitHub login
- `getStacks`: List all stacks accessible by the authenticated user with
  pagination support
- `getStackPermissions`: Query detailed team and user permissions for a
  specific stack

- Added `ListUserStacks()` to query accessible stacks via `/api/user/stacks`
- Added `ListStackTeamPermissions()` to query team access via
  `/api/stacks/{org}/{project}/{stack}/teams`
- Added `ListStackCollaborators()` to query user access via
  `/api/stacks/{org}/{project}/{stack}/collaborators`
- Enhanced existing `UserInfo` type to include `AvatarUrl` and `Email` fields

- Implemented four invoke function handlers in provider.go
- Added comprehensive property conversion helpers
- Added schema definitions for all four invoke functions with detailed
  input/output specifications

- Generated SDKs for all supported languages (TypeScript, Python, Go, .NET,
  Java)
- All new invoke functions are available across all language SDKs

- Added comprehensive YAML example (`yaml-permissions-query`) demonstrating
  all four invoke functions
- Created detailed README with usage examples, use cases, and conversion
  instructions
- Updated CHANGELOG.md with feature descriptions

- ✅ Added integration test `TestYamlPermissionsQueryExample` in
  `examples/examples_yaml_test.go` - **PASSING**
- ✅ All linting passes with zero issues
- ✅ Provider builds successfully
- ✅ All SDKs generate without errors
- ✅ Integration test validates both `getTeams` and `getStacks` data sources
  successfully query live data

These data sources enable several important scenarios:

1. **Audit Organization Access**: Get complete view of teams, members, and
   resource access
2. **User Access Review**: Quickly determine what teams and resources a user
   has access to
3. **Stack Discovery**: Find all accessible stacks across the organization
4. **Permission Analysis**: Understand exactly who has access to sensitive
   stacks

Fixes #509
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pulumi-Service Provider support for List Teams, Team Memberships, List Stacks, List Stack permissions

2 participants