feat: add support for workbench custom oauth integrations#47
feat: add support for workbench custom oauth integrations#47
Conversation
Adds support for configuring custom OAuth integrations in Workbench by implementing the oauth-clients.conf configuration file format. This feature allows users to configure multiple OAuth integrations (Box, Dropbox, Google Drive, etc.) for their Workbench instances, enabling data access from external APIs. Changes: - Add WorkbenchOAuthClientConfig struct to define OAuth client configuration - Add OAuthClients map field to WorkbenchSecretIniConfig - Add FetchAndSetOAuthClientSecrets() method to fetch secrets from vault - Integrate OAuth secret fetching into Workbench reconciliation - Add OAuth secrets to AWS SecretProviderClass - Generate CRD manifests and client code The implementation follows the exact same pattern as the existing Databricks integration: - Map keys become INI section headers - Existing reflection-based GenerateConfigMap() handles INI generation automatically - Secrets fetched using same pattern as Databricks - File mounted via existing secret-config volume at /mnt/secure-config/rstudio/oauth-clients.conf Fixes #46 Co-Authored-By: Claude <noreply@anthropic.com>
|
Claude finished @statik's task —— View job Review Complete
Submitted a code review with feedback on:
|
There was a problem hiding this comment.
Code Review
This PR follows the existing Databricks integration pattern well. The implementation is clean and consistent with the codebase conventions. A few observations:
API Changes (api/core/v1beta1/workbench_config.go)
Suggestion: Consider adding kubebuilder validation annotations for required fields. Based on the Workbench OAuth docs, client-id, authorization-url, and token-url appear to be required for a functional integration. This would provide early validation feedback rather than runtime errors.
Controller Changes (internal/controller/core/workbench.go)
-
Defensive nil check (line 76): The nil check only validates
OAuthClientsbut not the full path. Consider checkingw.Spec.SecretConfig.WorkbenchSecretIniConfigas well to prevent potential panics. -
Secret naming convention (line 86): The
dev-oauth-client-secret-%spattern usesintegrationNamedirectly. Consider:- Documenting this convention in the CRD description so users understand what secret name to create
- Sanitizing
integrationNameto prevent invalid characters in secret names
-
Inconsistent error handling (line 166 vs 160): OAuth client secret errors are fatal (returns error), while Databricks errors are non-fatal (logs and continues). Is this intentional? If OAuth secrets are always required when configured, the current approach is correct. Otherwise, consider aligning with the Databricks pattern.
-
DRY opportunity (lines 86 and 327): The secret key generation pattern
dev-oauth-client-secret-%sappears in two places. Consider extracting to a helper function for consistency.
Testing
Per the review guidelines checklist, unit and integration tests are not included in this PR. The PR description mentions a testing plan - would be good to either include tests in this PR or track them as follow-up.
Overall
The implementation is straightforward and follows established patterns. The changes are well-scoped and the CRD regeneration looks correct.
Adds comprehensive unit tests for the OAuth integration feature: - Test INI generation with multiple OAuth clients - Test kebab-case conversion of field names - Test comma-separated scopes array formatting - Test empty scopes handling - Test interaction with other config types Also fixes bug in WorkbenchSecretIniConfig.GenerateConfigMap() where slices in map-based configs were not converted to comma-separated strings. The fix ensures array fields (like scopes) are properly formatted as "scopes=read,write" instead of "scopes=[read write]". Co-Authored-By: Claude <noreply@anthropic.com>
|
✅ Unit tests added! Added 4 comprehensive unit tests for OAuth integration:
All tests passing. Also fixed a bug in |
|
🔧 Fixed CI formatting issue The first build failed due to inconsistent struct field alignment. Fixed the spacing in New build running: https://github.com/posit-dev/team-operator/actions/runs/21274383756 |
|
✅ CI Build Passed! All checks are passing. The PR is ready for review. Build: https://github.com/posit-dev/team-operator/actions/runs/21274383756 |
|
@ian-flores do you have advice on which cluster/site I should test this adhoc operator build on? |
Improvements to the custom OAuth integrations feature: 1. Error handling consistency: - OAuth secret fetching errors are now non-fatal (like Databricks) - Continues processing other integrations even if one fails - A missing secret will not block entire Workbench deployment 2. API documentation: - Added comprehensive kubebuilder comments to WorkbenchOAuthClientConfig - Documented required vs optional fields - Added validation markers (MinLength, Enum) - Links to official Workbench documentation 3. Validation for required fields: - Validates client-id, authorization-url, and token-url are present - Logs informative message listing missing fields - Skips integration gracefully if validation fails 4. Example CR: - Added config/samples/workbench_oauth_integrations.yaml - Shows Box, Google Drive, Dropbox, and custom API examples - Includes corresponding Kubernetes Secret example - Documents prerequisites and redirect URI configuration Co-Authored-By: Claude <noreply@anthropic.com>
Improvements AddedBased on feedback, I've implemented the following enhancements: 1. Error Handling Consistency 🔧
2. API Documentation 📝Added comprehensive kubebuilder comments to
3. Validation for Required Fields ✅Per the Workbench documentation, these fields are required:
The controller now validates these and logs a helpful message if any are missing: 4. Example CR 📄Added
Files changed in this commit:
|
Adds comprehensive controller-level tests for FetchAndSetOAuthClientSecrets: - TestOAuthClientSecrets: Happy path with multiple OAuth integrations - TestOAuthClientSecrets_NilOAuthClients: Verifies nil handling (no-op) - TestOAuthClientSecrets_MissingRequiredFields: Validates required field checking - TestOAuthClientSecrets_BackwardsCompatibility: Ensures existing configs unaffected These tests provide confidence that: - OAuth feature works correctly end-to-end - Existing Workbench deployments without OAuth are unaffected - Invalid integrations are skipped gracefully - Valid integrations are processed even when others fail Co-Authored-By: Claude <noreply@anthropic.com>
Additional Tests AddedAdded 4 controller-level tests for
Total test coverage: 8 unit tests (4 API-level + 4 controller-level) Also updated the PR description with explicit backwards compatibility notes and test coverage summary. |
@statik You can use |
Summary
Adds support for Workbench custom OAuth integrations by implementing the
oauth-clients.confconfiguration file format as documented at https://docs.posit.co/ide/server-pro/integration/custom-oauth.html.This feature allows users to configure multiple OAuth integrations (Box, Dropbox, Google Drive, etc.) for their Workbench instances, enabling data access from external APIs.
Backwards Compatibility
✅ This change is fully backwards compatible:
OAuthClientsfield is optional - existing Workbench CRs without it continue to work unchangedOAuthClientsis handled as a no-op (verified by unit test)Implementation Details
WorkbenchOAuthClientConfigstruct with fields for name, client-id, client-secret, authorization-url, token-url, token-endpoint-auth-method, and scopesOAuthClientsmap field toWorkbenchSecretIniConfig- map keys become INI section headersFetchAndSetOAuthClientSecrets()method to fetch secrets from vault (K8s Secrets or AWS Secrets Manager)ReconcileWorkbench()reconciliation loop (non-fatal errors)GenerateConfigMap()where slices in map-based configs were not converted to comma-separated stringsTest Coverage
Unit Tests (8 total)
TestWorkbenchSecretConfig_GenerateSecretData_WithOAuthClients- INI generation with multiple clientsTestWorkbenchSecretConfig_GenerateSecretData_WithOAuthClients_EmptyScopes- Empty scopes handlingTestWorkbenchSecretConfig_GenerateSecretData_WithMultipleConfigs- OAuth + other configs togetherTestOAuthClientSecrets- Secret fetching happy pathTestOAuthClientSecrets_NilOAuthClients- Nil handling (no-op)TestOAuthClientSecrets_MissingRequiredFields- Validation skips invalid, processes validTestOAuthClientSecrets_BackwardsCompatibility- Existing configs unaffectedWhat the tests verify:
Example Usage
See
config/samples/workbench_oauth_integrations.yamlfor complete examples.Files Changed
api/core/v1beta1/workbench_config.goapi/core/v1beta1/workbench_config_test.gointernal/controller/core/workbench.gointernal/controller/core/workbench_test.goconfig/samples/workbench_oauth_integrations.yamlconfig/crd/bases/core.posit.team_workbenches.yamlCloses #46
🤖 Generated with Claude Code