Header für Organisationsbeschränkungen vor der Konfiguration eines ausgehenden Proxys testen

Auf dieser Seite wird beschrieben, wie Google Cloud Administratoren Organisationsbeschränkungen testen können, ohne einen Ausgehende-Proxy konfigurieren zu müssen.

So erstellen und testen Sie den Abschnitt zu organisatorischen Einschränkungen:

  1. Verwenden Sie den Befehl gcloud organizations list, um die Google Cloud Organisations-ID der Organisation abzurufen:

        gcloud organizations list
    

    Die Beispielausgabe sieht so aus:

        DISPLAY_NAME: Organization A
        ID: 123456789
        DIRECTORY_CUSTOMER_ID: a1b2c3d4
    
  2. Nachdem du die Organisations-ID abgerufen hast, erstellst du die JSON-Darstellung für den Headerwert im folgenden Format:

     {
     "resources": ["organizations/123456789"],
      "options": "strict"
     }
    
  3. Codieren Sie den Wert für den Anfrageheader gemäß den Spezifikationen in RFC 4648 Abschnitt 5.

    Wenn die JSON-Darstellung für den Headerwert beispielsweise in der Datei authorized_orgs.json gespeichert ist, sieht die Codierung mit basenc so aus:

     $ OR_HEADER=`cat authorized_orgs.json | basenc --base64url -w0`
     $ echo $OR_HEADER
    ewogInJlc291cmNlcyI6IFsib3JnYW5pemF0aW9ucy8xMjM0NTY3ODkiXQogIm9wdGlvbnMiOiAic3RyaWN0Igp9Cgo=
    
  4. Wenn Sie testen möchten, ob die Headerkonfiguration den Zugriff auf eine Ressource in einer autorisiertenGoogle Cloud -Organisation zulässt, erstellen Sie eine Curl-Anfrage an eine Ressource in einer autorisiertenGoogle Cloud -Organisation.Google Cloud Hier ist ein Beispiel für eine curl-Anfrage:

    # Get auth token
    $ TOKEN=$(gcloud auth print-access-token)
    
    # Make a request that includes the organization restriction header; this call makes a request to the logging API for a project within the same organization listed in the header
    $ curl -H "X-Goog-Allowed-Resources: ${OR_HEADER}" -X POST -d '{"projectIds":
    ["my-project-123"]}' -H 'Content-Type: application/json' -H "Authorization: Bearer ${TOKEN}" "https://logging.googleapis.com/v2/entries:list"
    # A successful request returns log entries in this project
    
  5. Wenn Sie testen möchten, ob die Headerkonfiguration den Zugriff auf eine Ressource außerhalb der autorisiertenGoogle Cloud -Organisation verweigert, erstellen Sie eine Curl-Anfrage an eine Ressource außerhalb einer autorisiertenGoogle Cloud -Organisation. Hier ist ein Beispiel für eine curl-Anfrage:

    # Get auth token
    $ TOKEN=$(gcloud auth print-access-token)
    
    # Make a request that includes the organization restriction header; this call makes a request to the logging API for a project not within the same organization listed in the header
    $ curl -H "X-Goog-Allowed-Resources: ${OR_HEADER}" -X POST -d '{"projectIds": ["other-project-123"]}' -H 'Content-Type: application/json' -H "Authorization: Bearer ${TOKEN}" "https://logging.googleapis.com/v2/entries:list" 
    {
      "error": {
     "code": 403,
        "message": "Access denied by organization restriction. Contact your administrator for additional information.",
        "status": "PERMISSION_DENIED",
        "details": [
          {
            "@type": "type.googleapis.com/google.rpc.ErrorInfo",
            "reason": "ORG_RESTRICTION_VIOLATION",
            "domain": "googleapis.com",
            "metadata": {
              "service": "logging.googleapis.com",
              "consumer": "other-project-123"
            }
          }
        ]
      }
    }
    
    

    Eine Fehlermeldung vom Typ „Zugriff verweigert“ gibt an, dass die Anfrage an die Ressource abgelehnt wurde.

Nächste Schritte