Add policy publishing workflow and update release workflow for policy hub integration#27
Add policy publishing workflow and update release workflow for policy hub integration#27DakshithaS wants to merge 4 commits intowso2:mainfrom
Conversation
WalkthroughAdds a new GitHub Actions workflow Changes
Sequence DiagramsequenceDiagram
participant GHA as GitHub Actions
participant FS as File System
participant API as Policy Hub API
GHA->>GHA: Receive inputs (policy_name, minor_version)
GHA->>FS: Verify `docs/` and `policies/` directories exist
GHA->>FS: Read `policies/<policy>/metadata.json`
GHA->>GHA: Validate metadata fields and match inputs
GHA->>GHA: Validate categories against whitelist
GHA->>FS: Package `docs/` and assets into `policy-version.zip`
GHA->>API: POST package or definition with `api-key` header
API-->>GHA: Return HTTP response (success/error)
GHA->>GHA: Log response, show errors, cleanup artifacts
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~40 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In @.github/workflows/publish-policy.yml:
- Around line 34-81: The POLICY_NAME validation must reject unsafe values—modify
the validation block that sets and checks POLICY_NAME to trim whitespace and
enforce a strict allowed pattern (e.g., only letters, numbers, hyphen and
underscore: /^[A-Za-z0-9_-]+$/), and explicitly disallow any slashes or path
traversal tokens like ".."; update the error message accordingly and only export
POLICY_NAME (and derived paths VERSION_DIR, POLICIES_DIR) to GITHUB_ENV after
this stronger validation passes so filesystem and URL usage (references:
POLICY_NAME, DOCS_POLICY_DIR, VERSION_DIR, POLICIES_DIR) cannot be tricked by
whitespace or traversal.
- Around line 256-294: Replace the eval-based string building with a safe
array-style curl invocation and remove --insecure: build an args array (e.g.,
curl_args=("-s" "-w" "%{http_code}" "-o" "response.txt" "-X" "POST" "--max-time"
"30" "--connect-timeout" "10"
"$API_URL/policies/$METADATA_NAME/versions/$METADATA_VERSION")) then append form
fields with curl_args+=("-F"
"metadata=@$VERSION_DIR/metadata.json;type=application/json") and
curl_args+=("-F" "docs=@$GITHUB_WORKSPACE/$ZIP_NAME"); if POLICY_HUB_TOKEN is
set, append curl_args+=("-H" "api-key: $POLICY_HUB_TOKEN"); run curl with
"HTTP_STATUS=$(curl "${curl_args[@]}")" (no eval) and remove the --insecure
flag; keep using response.txt for the body and reuse existing checks on
HTTP_STATUS and response.txt.
- Around line 105-211: The categories validation can be bypassed when
.categories is missing, null, or not an array because the while loop reads
nothing; enable strict shell failure and add an explicit jq type/length check
before iterating: set strict mode (set -euo pipefail) at the top of this step,
validate with jq that .categories is an array and has length > 0 (e.g. using jq
'type=="array" and length>0'), fail with a clear error if that check fails, then
proceed to use jq -r '.categories[]' "$METADATA_FILE" to iterate and compare
entries against CLEAN_CATS/ PREDEFINED_CATS as currently implemented.
Purpose
Add a GitHub Actions workflow for publishing policies to the policy hub, including comprehensive validation of policy metadata, packaging, and API publishing. Update the existing release workflow to use environment variables for policy hub URL and adjust the API endpoint for policy registration.
Goals
Approach
publish-policy.ymlworkflow with steps for input validation, metadata parsing, package creation, and API publishingrelease-policy.ymlto usevars.POLICY_HUB_URLand changed API endpoint to/policies/{policy}/versions/{version}/releaseRelated Issue
Summary by CodeRabbit