GCP - Federation Abuse

जानें AWS हैकिंग को शून्य से हीरो तक htARTE (HackTricks AWS Red Team Expert) के साथ!

HackTricks का समर्थन करने के अन्य तरीके:

OIDC - Github क्रियाएँ दुरुपयोग

GCP

Github Actions से एक Github रिपो को GCP सेवा खाते को पहुंचने के लिए निम्नलिखित चरण आवश्यक हैं:

  • चाहिए अनुमतियों के साथ सेवा खाते बनाएं जिससे github actions से पहुंच मिले:

projectId=FIXME
gcloud config set project $projectId

# Create the Service Account
gcloud iam service-accounts create "github-demo-sa"
saId="github-demo-sa@${projectId}.iam.gserviceaccount.com"

# Enable the IAM Credentials API
gcloud services enable iamcredentials.googleapis.com

# Give permissions to SA

gcloud projects add-iam-policy-binding $projectId \
--member="serviceAccount:$saId" \
--role="roles/iam.securityReviewer"
  • एक नया वर्कलोड आइडेंटिटी पूल उत्पन्न करें:

# Create a Workload Identity Pool
poolName=wi-pool

gcloud iam workload-identity-pools create $poolName \
--location global \
--display-name $poolName

poolId=$(gcloud iam workload-identity-pools describe $poolName \
--location global \
--format='get(name)')
  • एक नया वर्कलोड आइडेंटिटी पूल OIDC प्रदाता जेनरेट करें जो github क्रियाएँ (इस स्थिति में संगठन/रिपो नाम द्वारा) पर विश्वास करता है:

attributeMappingScope=repository # could be sub (GitHub repository and branch) or repository_owner (GitHub organization)

gcloud iam workload-identity-pools providers create-oidc $poolName \
--location global \
--workload-identity-pool $poolName \
--display-name $poolName \
--attribute-mapping "google.subject=assertion.${attributeMappingScope},attribute.actor=assertion.actor,attribute.aud=assertion.aud,attribute.repository=assertion.repository" \
--issuer-uri "https://token.actions.githubusercontent.com"

providerId=$(gcloud iam workload-identity-pools providers describe $poolName \
--location global \
--workload-identity-pool $poolName \
--format='get(name)')
  • अंत में, प्रदाता से मुख्य को सेवा मुख्य का उपयोग करने दें:

gitHubRepoName="repo-org/repo-name"
gcloud iam service-accounts add-iam-policy-binding $saId \
--role "roles/iam.workloadIdentityUser" \
--member "principalSet://iam.googleapis.com/${poolId}/attribute.${attributeMappingScope}/${gitHubRepoName}"

ध्यान दें कि पिछले सदस्य में हम org-name/repo-name को शर्तें बता रहे हैं ताकि सेवा खाता तक पहुंच सकें (जो इसे और प्रतिबंधक बनाने वाले अन्य पैरामीटर भी उपयोग किए जा सकते हैं जैसे शाखा).

हालांकि, सेवा खाता तक पहुंचने की अनुमति देना भी संभव है सभी github को पहुंचने की सेवा खाता बनाकर निम्नलिखित जैसा प्रदाता बनाना:

# एक वर्कलोड आईडेंटिटी पूल बनाएं
poolName=wi-pool2

gcloud iam workload-identity-pools create $poolName \
--location global \
--display-name $poolName

poolId=$(gcloud iam workload-identity-pools describe $poolName \
--location global \
--format='get(name)')

gcloud iam workload-identity-pools providers create-oidc $poolName \
--project="${projectId}" \
--location="global" \
--workload-identity-pool="$poolName" \
--display-name="Demo provider" \
--attribute-mapping="google.subject=assertion.sub,attribute.actor=assertion.actor,attribute.aud=assertion.aud" \
--issuer-uri="https://token.actions.githubusercontent.com"

providerId=$(gcloud iam workload-identity-pools providers describe $poolName \
--location global \
--workload-identity-pool $poolName \
--format='get(name)')

# वाइल्डकार्ड की जाँच करें
gcloud iam service-accounts add-iam-policy-binding "${saId}" \
--project="${projectId}" \
--role="roles/iam.workloadIdentityUser" \
  --member="principalSet://iam.googleapis.com/${poolId}/*"

इस मामले में कोई भी github actions से सेवा खाता तक पहुंच सकता है, इसलिए हमेशा सदस्य कैसे परिभाषित है की जाँच करना महत्वपूर्ण है। हमेशा यही होना चाहिए:

attribute.{custom_attribute}:principalSet://iam.googleapis.com/projects/{project}/locations/{location}/workloadIdentityPools/{pool}/attribute.{custom_attribute}/{value}

Github

याद रखें कि ${providerId} और ${saId} के लिए उनके संबंधित मानों को बदल दें:

name: Check GCP action
on:
workflow_dispatch:
pull_request:
branches:
- main

permissions:
id-token: write

jobs:
Get_OIDC_ID_token:
runs-on: ubuntu-latest
steps:
- id: 'auth'
name: 'Authenticate to GCP'
uses: 'google-github-actions/auth@v0.3.1'
with:
create_credentials_file: 'true'
workload_identity_provider: '${providerId}'
service_account: '${saId}'
- id: 'gcloud'
name: 'gcloud'
run: |-
gcloud auth login --brief --cred-file="${{ steps.auth.outputs.credentials_file_path }}"
gcloud auth list
gcloud projects list
जानें AWS हैकिंग को शून्य से हीरो तक htARTE (HackTricks AWS Red Team Expert)!

दूसरे तरीके HackTricks का समर्थन करने के लिए:

Last updated