Header für Organisationseinschränkungen testen, bevor Sie einen Proxy für ausgehenden Traffic konfigurieren

Auf dieser Seite wird beschrieben, wie Google Cloud-Administratoren Organisationseinschränkungen testen können, ohne einen Proxy für ausgehenden Traffic konfigurieren zu müssen.

So erstellen und testen Sie den Header für Organisationseinschränkungen:

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

        gcloud organizations list
    

    Im Folgenden sehen Sie die Beispielausgabe:

        DISPLAY_NAME: Organization A
        ID: 123456789
        DIRECTORY_CUSTOMER_ID: a1b2c3d4
    
  2. Nachdem Sie die Organisations-ID abgerufen haben, stellen Sie die JSON-Darstellung für den Header-Wert im folgenden Format zusammen:

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

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

     $ OR_HEADER=`cat authorized_orgs.json | basenc --base64url -w0`
     $ echo $OR_HEADER
    ewogInJlc291cmNlcyI6IFsib3JnYW5pemF0aW9ucy8xMjM0NTY3ODkiXQogIm9wdGlvbnMiOiAic3RyaWN0Igp9Cgo=
    
  4. Erstellen Sie eine curl-Anfrage an eine Ressource in einer autorisierten Google Cloud-Organisation, um zu testen, ob die Headerkonfiguration den Zugriff auf eine Ressource in einer autorisierten Google Cloud-Organisation zulässt. 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. Erstellen Sie eine curl-Anfrage an eine Ressource außerhalb einer autorisierten Google Cloud-Organisation, um zu testen, ob die Headerkonfiguration den Zugriff auf eine Ressource verweigert, die sich außerhalb der autorisierten Google Cloud-Organisation befindet. 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 „Zugriff verweigert“ gibt an, dass die Anfrage an die Ressource abgelehnt wurde.

Nächste Schritte