-
Notifications
You must be signed in to change notification settings - Fork 8
Add Pipeline Step Secrets support to Python SDK and CLI #830
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
base: master
Are you sure you want to change the base?
Conversation
- Implement step_version_secrets parsing in pipeline_builder.py - Add helper methods to Pipeline client (get_pipeline_version, create_pipeline_version, list_step_secrets) - Include step secrets in lockfile generation - Update pipeline config template with example step secrets - Add comprehensive test coverage for step secrets functionality Co-authored-by: ydixit-clarifai <[email protected]>
Co-authored-by: ydixit-clarifai <[email protected]>
Add note explaining that Python API uses simplified format without 'secrets' wrapper compared to YAML configuration Co-authored-by: ydixit-clarifai <[email protected]>
- Change info logging to debug level to reduce verbosity - Rename 'secrets' variable to 'secret_refs' for clarity - Add comments explaining that only references (not values) are handled - Remove per-secret logging to minimize exposure surface - Address CodeQL security alerts (false positives documented) Co-authored-by: ydixit-clarifai <[email protected]>
| # Secret references are like "users/user123/secrets/my-api-key" | ||
| secret_refs = step_config.get("secrets", {}) | ||
| if not secret_refs: | ||
| logger.debug(f"No secret references found for step {step_ref}, skipping") |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information High
sensitive data (secret)
This expression logs
sensitive data (secret)
This expression logs
sensitive data (secret)
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 days ago
To fix this issue, avoid logging the value of step_ref in log statements related to secret management, especially when those references may be sensitive or could leak implementation details. Specifically, the log message on line 396 should be reworded or removed, so as not to include the step_ref value. The recommended approach is to log a generic message that does not reveal the step or key name, or else omit the log entirely if it's not essential for debugging. No new imports or method definitions are necessary, and only the single log statement on line 396 needs to be changed.
-
Copy modified line R396
| @@ -393,7 +393,7 @@ | ||
| # Secret references are like "users/user123/secrets/my-api-key" | ||
| secret_refs = step_config.get("secrets", {}) | ||
| if not secret_refs: | ||
| logger.debug(f"No secret references found for step {step_ref}, skipping") | ||
| logger.debug("No secret references found for step, skipping") | ||
| continue | ||
|
|
||
| # Create StepSecretConfig proto |
|
|
||
| # Add to pipeline version config | ||
| pipeline_version.config.step_version_secrets[step_ref].CopyFrom(step_secret_config) | ||
| logger.debug(f"Configured secret references for step {step_ref}") |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information High
sensitive data (secret)
This expression logs
sensitive data (secret)
This expression logs
sensitive data (secret)
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 days ago
To fix the problem, we should avoid logging any information derived from step_ref if it could contain sensitive or identifying information. The log statement on line 406 currently logs step_ref directly. The best approach is to replace this log statement with text that does not output sensitive information. For example, you can simply indicate that secret references have been configured for a step, without using a dynamic identifier, or even suppress the log altogether if it serves no unique troubleshooting purpose. Alternatively, you may redacted the reference (e.g., log a hash, length, or generic indicator) if visibility is required, but here the safest approach is to remove or generalize the message.
Changes required:
- Edit line 406 in
clarifai/runners/pipelines/pipeline_builder.pyto remove or generalize the log statement so thatstep_refis not logged. - No new methods or imports needed.
-
Copy modified line R406
| @@ -403,7 +403,7 @@ | ||
|
|
||
| # Add to pipeline version config | ||
| pipeline_version.config.step_version_secrets[step_ref].CopyFrom(step_secret_config) | ||
| logger.debug(f"Configured secret references for step {step_ref}") | ||
| logger.debug("Configured secret references for a pipeline step.") | ||
|
|
||
| def create_pipeline(self) -> tuple[bool, str]: | ||
| """Create the pipeline using PostPipelines RPC. |
|
@copilot The stepversionsecret should be part of the orchestration spec in each of the pipeline steps. Why Map<SecretName, SecretRef>? For one pipeline, While for another one, |
Per review feedback, step_version_secrets should be part of the pipeline config section (matching the proto structure PipelineVersion.config.step_version_secrets) rather than nested inside orchestration_spec.
Changes:
- Move step_version_secrets from orchestration_spec to config section in YAML structure
- Update pipeline_builder.py to read from config section
- Update lockfile generation to preserve secrets in config section
- Update templates and documentation to show correct structure
- Update all tests to use new config structure
The new YAML structure is:
```yaml
pipeline:
orchestration_spec:
argo_orchestration_spec: |
...
config:
step_version_secrets:
step-0:
secrets:
API_KEY: users/user123/secrets/my-api-key
```
Co-authored-by: ydixit-clarifai <[email protected]>
Updated the implementation to match the proto structure. The The new YAML structure is: pipeline:
orchestration_spec:
argo_orchestration_spec: |
...
config:
step_version_secrets:
step-0:
secrets:
API_KEY: users/user123/secrets/my-api-keyAll tests updated and passing. Changes in commit 9cdadbd. |
Clarifai backend now supports Pipeline Step Secrets for step-level secret isolation. This PR implements SDK and CLI support for the feature.
Changes
Pipeline Builder (
clarifai/runners/pipelines/pipeline_builder.py)step_version_secretsfromconfigsection in config.yaml (matching proto structurePipelineVersion.config.step_version_secrets)PipelineVersion.configvia new_add_step_version_secrets()methodprepare_lockfile_with_step_versions(),generate_lockfile_data())Pipeline Client (
clarifai/client/pipeline.py)get_pipeline_version()- retrieve version with secrets configcreate_pipeline_version()- create version with secrets viaPatchPipelineVersionslist_step_secrets()- query secrets for all/specific steps{step_ref: {secret_name: secret_path}}(nosecretswrapper)CLI Template (
clarifai/cli/templates/pipeline_templates.py)step_version_secretsexample to generated pipeline configs in correctconfigsectionDocumentation (
docs/pipeline_step_secrets.md)secretskey, Python API omits it)Usage
Config YAML:
Python SDK:
Security
Backward Compatibility
step_version_secretsis optionalOriginal prompt
This section details on the original issue you should resolve
<issue_title>Pipeline Step Secrets Feature Adoption in Python SDK and CLI</issue_title>
<issue_description>## Overview
Clarifai backend now supports Pipeline Step Secrets—enabling different pipeline steps to access distinct sets of secrets with step-level isolation. This document outlines the technical changes required to adopt this feature in the Python SDK and CLI, ensuring compatibility with updated API fields and backend functionality.
API Feature Summary
1. New Proto Fields
map<string, StepSecretConfig>step1,step2, ...)StepSecretConfigmap<string, string>API_KEY)users/user123/secrets/my-api-key)2. Updated API Endpoints
3. Example API Usage
Creation
{ "pipeline_version": { "config": { "step_version_secrets": { "step1": { "secrets": { "API_KEY": "users/user123/secrets/my-api-key", "DB_PASSWORD": "users/user123/secrets/db-secret" } }, "step2": { "secrets": { "EMAIL_TOKEN": "users/user123/secrets/email-token" } } } } } }Python SDK Changes
1. Proto/Model Updates
PipelineVersionConfigincludes thestep_version_secretsfield.StepSecretConfigmodel/class for mapping secrets per step.2. Client Method Updates
get_pipeline_version()to handle new step secrets field.create_pipeline_version()to accept step secrets.3. Helper Methods (Recommended)
add_step_secret(step_ref, secret_name, secret_ref)remove_step_secret(step_ref, secret_name)list_step_secrets(step_ref)CLI Changes
1. Command Updates
clarifai pipeline version createto accept step secrets specified in the orchestration spec (config.yaml), not as CLI parameters.clarifai pipeline version getto display step secrets.2. Config File Integration (Orchestration Spec)
Step secrets should be defined within the
config.yamlfile as part of the pipeline orchestration specification, matching the API schema.Example
config.yaml:CLI usage examples:
All step secrets should be managed via the spec file; do not support CLI flags for individual secrets.
3. Output Formatting
Backward Compatibility
step_version_secretsis optional; existing pipelines unaffected.Testing Requirements
1. Unit Tests
2. Integration Tests
3. Example Code & Documentation
Security Considerations
Additional Context
---...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.