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

Bevor Sie einen Proxy für ausgehenden Traffic konfigurieren, können Sie den Header für Organisationsbeschränkungen direkt mit einem Tool wie curl testen. Mit diesen Tests können Sie prüfen, ob Anfragen an autorisierteCloud de Confiance by S3NS -Organisationen erfolgreich sind und Anfragen an nicht autorisierte Organisationen blockiert werden.

Header für Organisationsbeschränkungen testen

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

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

        gcloud organizations list
    

    Hier sehen Sie die Beispielausgabe:

        DISPLAY_NAME: Organization A
        ID: 123456789
        DIRECTORY_CUSTOMER_ID: a1b2c3d4
    
  2. Nachdem Sie die Organisations-ID abgerufen haben, erstellen Sie 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 über 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 autorisiertenCloud de Confiance by S3NS -Organisation zulässt, erstellen Sie eine curl-Anfrage an eine Ressource in einer autorisiertenCloud de Confiance by S3NS -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 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 autorisierten OrganisationCloud de Confiance by S3NS verweigert, erstellen Sie eine curl-Anfrage an eine Ressource außerhalb einer autorisierten OrganisationCloud de Confiance by S3NS . 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, dass der Zugriff verweigert wurde, weist darauf hin, dass die Anfrage an die Ressource abgelehnt wurde.

Nächste Schritte