Skip to content
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

add google identity federation #79

Merged
merged 1 commit into from
Jan 28, 2025
Merged

Conversation

SergiiGlad
Copy link
Contributor

@SergiiGlad SergiiGlad commented Jan 26, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for Google Secret Manager integration with workload identity federation
    • Introduced a new Helm chart for GCP Workload Identity Federation webhook
  • Configuration Updates

    • Updated workload identity pool provider configuration
    • Added new secret management variables for K3s JWKS

The changes enhance security and identity management for Kubernetes deployments on Google Cloud Platform.

Copy link

coderabbitai bot commented Jan 26, 2025

Walkthrough

The pull request introduces changes to Terraform configurations for Google Cloud Platform (GCP) workload identity federation. A new secret variable for K3s JWKS (JSON Web Key Set) is added, and a new data block is created to access this secret. The workload identity pool provider is renamed, and a new Helm chart is deployed to manage workload identity federation webhook in the Kubernetes cluster.

Changes

File Change Summary
Terraform/GCP/iam/variables.tf Added google_secret_name_k3s_jwks variable with type string and default value "k3s-jwks"
Terraform/GCP/iam/wif.tf - Renamed workload identity pool provider from onprem-cluster to k3s_provider
- Added google_secret_manager_secret_version_access data block for K3s JWKS
- Integrated JWKS secret into provider configuration
Terraform/GCP/k8s/wif.tf Added Helm release gcp_wif_webhook for deploying workload identity federation webhook in "csi" namespace

Sequence Diagram

sequenceDiagram
    participant SM as Secret Manager
    participant WIF as Workload Identity Federation
    participant K8s as Kubernetes Cluster
    
    SM->>WIF: Retrieve JWKS Secret
    WIF->>WIF: Configure Provider with JWKS
    WIF->>K8s: Deploy Webhook
    K8s-->>WIF: Webhook Installed
Loading

Poem

🐰 A Rabbit's Ode to Identity's Grace 🔑

In GCP's cloud, secrets take flight,
JWKS dancing with federation's might
Webhooks whisper, providers rename,
Terraform weaves its infrastructure frame
Identity's magic, now clear and bright! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
Terraform/GCP/iam/wif.tf (1)

Incorrect namespace restriction blocks CSI driver access

The attribute condition restricts workload identity federation to the "csi" namespace, but the GCP CSI driver is deployed in the "gce-pd-csi-driver" namespace. This will prevent the CSI driver from accessing GCP resources.

Update the attribute condition:

-  attribute_condition = "attribute.kubernetes_namespace==\"csi\""
+  attribute_condition = "attribute.kubernetes_namespace==\"gce-pd-csi-driver\""

Also, consider implementing the security enhancements suggested in the original review for the OIDC configuration.

🔗 Analysis chain

Line range hint 14-27: Review the namespace restriction in attribute condition.

The attribute condition attribute.kubernetes_namespace=="csi" restricts workload identity federation to the "csi" namespace only. Verify if this is intentional or if other namespaces need access.

Also, consider enhancing the OIDC configuration security:

   oidc {
     issuer_uri        = var.wif_issuer_uri
-    allowed_audiences = ["sts.googleapis.com"]
+    allowed_audiences = [var.workload_identity_audience]
     jwks_json         = data.google_secret_manager_secret_version_access.k3s_jwks.secret_data
   }
   attribute_mapping = {
     "google.subject"                 = "assertion.sub"
     "attribute.kubernetes_namespace" = "assertion[\"kubernetes.io\"][\"namespace\"]"
+    "attribute.aud"                 = "assertion.aud"
   }
-  attribute_condition = "attribute.kubernetes_namespace==\"csi\""
+  attribute_condition = "attribute.kubernetes_namespace==\"csi\" && attribute.aud==\"${var.workload_identity_audience}\""

Run this script to verify namespace usage:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential workload identity users in other namespaces
rg -l "serviceAccountName|workloadIdentity" | xargs rg "namespace:|serviceAccountName:"

Length of output: 3029

🧹 Nitpick comments (2)
Terraform/GCP/k8s/wif.tf (1)

3-3: Consider using a version reference instead of a fixed chart path.

Using a fixed path to a specific chart version makes updates harder to track and maintain. Consider:

  1. Moving the chart to a proper Helm repository
  2. Using a version variable for easier updates
-  chart            = "../../k8s/infrastructure/charts/gcp-workload-identity-federation-webhook-0.4.6.tgz"
+  repository       = "https://your-helm-repo"
+  chart            = "gcp-workload-identity-federation-webhook"
+  version          = var.wif_webhook_version
Terraform/GCP/iam/variables.tf (1)

48-52: Add validation rules for the secret name variable.

Consider adding validation rules to ensure the secret name follows GCP naming conventions.

 variable "google_secret_name_k3s_jwks" {
   type        = string
   description = "Google secret name for k3s jwks"
   default     = "k3s-jwks"
+  validation {
+    condition     = can(regex("^[a-zA-Z0-9-_]*$", var.google_secret_name_k3s_jwks))
+    error_message = "Secret name must only contain alphanumeric characters, hyphens, and underscores."
+  }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bdcd964 and 101d7e8.

⛔ Files ignored due to path filters (1)
  • k8s/infrastructure/charts/gcp-workload-identity-federation-webhook-0.4.6.tgz is excluded by !k8s/**/*.tgz and included by k8s/**
📒 Files selected for processing (3)
  • Terraform/GCP/iam/variables.tf (1 hunks)
  • Terraform/GCP/iam/wif.tf (2 hunks)
  • Terraform/GCP/k8s/wif.tf (1 hunks)
🔇 Additional comments (1)
Terraform/GCP/k8s/wif.tf (1)

1-9: Add configuration values for the Helm release.

The Helm release lacks essential configuration values that might be needed for proper webhook operation:

  • Resource requests and limits
  • Webhook configuration parameters
  • Logging settings

Please verify the required configuration by checking the chart's documentation:

✅ Verification successful

Basic Helm configuration is sufficient for the GCP WIF webhook

The current configuration is adequate because:

  • The webhook's primary functionality relies on the GCP Workload Identity Federation setup, which is properly configured in Terraform/GCP/iam/wif.tf
  • The chart (from pfnet-research) is designed to work with minimal configuration, automatically handling pod mutations based on the cluster's WIF configuration
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Extract and check the chart documentation
mkdir -p /tmp/chart && cd /tmp/chart
tar xf ../../k8s/infrastructure/charts/gcp-workload-identity-federation-webhook-0.4.6.tgz
cat */README.md */values.yaml

Length of output: 430


Script:

#!/bin/bash
# Search for the chart file and related documentation
echo "=== Searching for chart files ==="
fd -t f "gcp-workload-identity-federation-webhook.*\.tgz" || true

echo -e "\n=== Searching for chart documentation ==="
fd -t f "values\.ya?ml" -t f "README\.md" -t f "Chart\.ya?ml" | grep -i "workload.*identity\|wif" || true

echo -e "\n=== Searching for example configurations ==="
rg -l "gcp-workload-identity-federation-webhook" || true

Length of output: 755


Script:

#!/bin/bash
# Search GitHub for the chart repository
gh search repos "gcp-workload-identity-federation-webhook" --limit 5 || true

echo -e "\n=== Checking if chart exists in common Helm repositories ==="
helm search hub gcp-workload-identity-federation-webhook || true

echo -e "\n=== Looking for any related configuration in the codebase ==="
rg -A 5 -B 5 "workload.*identity" || true

Length of output: 2726

Comment on lines +2 to +5
data "google_secret_manager_secret_version_access" "k3s_jwks" {
project = var.project
secret = var.google_secret_name_k3s_jwks
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for secret access.

The secret access should be handled gracefully in case of failures. Consider using a lifecycle block to handle secret access errors.

 data "google_secret_manager_secret_version_access" "k3s_jwks" {
   project = var.project
   secret  = var.google_secret_name_k3s_jwks
+  lifecycle {
+    postcondition {
+      condition     = self.secret_data != ""
+      error_message = "Failed to retrieve JWKS from Secret Manager"
+    }
+  }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
data "google_secret_manager_secret_version_access" "k3s_jwks" {
project = var.project
secret = var.google_secret_name_k3s_jwks
}
data "google_secret_manager_secret_version_access" "k3s_jwks" {
project = var.project
secret = var.google_secret_name_k3s_jwks
lifecycle {
postcondition {
condition = self.secret_data != ""
error_message = "Failed to retrieve JWKS from Secret Manager"
}
}
}

@DmyMi DmyMi merged commit 47e93f5 into main Jan 28, 2025
1 check passed
@DmyMi DmyMi deleted the feature/csi-driver-provider-gcp branch January 28, 2025 09:12
SergiiGlad added a commit that referenced this pull request Jan 28, 2025
@coderabbitai coderabbitai bot mentioned this pull request Jan 28, 2025
DmyMi pushed a commit that referenced this pull request Jan 28, 2025
* upgarde mysql 8.4.4

* edit new wi pool name

* add google identity federation (#79)
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.

2 participants