AWS::CloudFormation::Authentication - AWS CloudFormation

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

AWS::CloudFormation::Authentication

使用 AWS::CloudFormation::Authentication 資源來指定您使用 AWS::CloudFormation::Init 資源指定之檔案或來源的身分驗證憑證。

若要包含您使用 AWS::CloudFormation::Init 指定之檔案或來源的身分驗證資訊,請使用 uris 屬性 (若來源為 URI) 或 buckets 屬性 (若來源位於 Amazon S3 儲存貯體)。如需檔案的詳細資訊,請參閱檔案。如需來源的詳細資訊,請參閱 來源

您也可以在 AWS::CloudFormation::Init 資源中直接指定檔案的身分驗證資訊。資源的 files 金鑰包含名為 authentication 的屬性。您可以使用 authentication 屬性將在 資源中定義的身分驗證資訊,直接與檔案建立關聯。AWS::CloudFormation::Authentication

對於 檔案, 會依下列順序 AWS CloudFormation 尋找身分驗證資訊:

  1. authentication AWS::CloudFormation::Init 金鑰的 files 屬性。

  2. uris 資源的 bucketsAWS::CloudFormation::Authentication 屬性。

若為來源,CloudFormation 會在 AWS::CloudFormation::Authentication 資源的 urisbuckets 屬性中尋找身分驗證資訊。

語法

若要在您的 CloudFormation 範本中宣告此實體,請使用下列語法:

使用 AWS::CloudFormation::Authentication 類型時,您應該清楚下列事項:

  • 與大多數的 CloudFormation 資源不同,AWS::CloudFormation::Authentication 類型不包含名為屬性的區塊,而是包含一個使用者命名的區塊清單,其中每一個都包含其自身的身分驗證屬性。

    並非所有屬性都屬於每一種身分驗證類型。請參閱 type 屬性以取得詳細資訊。

  • 與大多數的 CloudFormation 資源不同,屬性名稱使用小寫連字 (camel case)。

JSON

{ "Type" : "AWS::CloudFormation::Authentication" { "String" : { "accessKeyId" : String, "buckets" : [ String, ... ], "password" : String, "secretKey" : String, "type" : String, "uris" : [ String, ... ], "username" : String, "roleName" : String } } }

YAML

Type: AWS::CloudFormation::Authentication String: accessKeyId: String buckets: - String password: String secretKey: String type: String uris: - String username: String roleName: String

屬性

accessKeyId

指定 S3 身分驗證的存取金鑰 ID。

必要:有條件限制。只有在 type 屬性設為 S3 時,才能指定此項目。

類型:字串

buckets

要和 S3 身分驗證憑證建立關聯的 Amazon S3 儲存貯體逗號分隔清單。

必要:有條件限制。只有在 type 屬性設為 S3 時,才能指定此項目。

類型:字串值清單

password

指定基本身分驗證的密碼。

必要:有條件限制。只有在 type 屬性設為 basic 時,才能指定此項目。

類型:字串

secretKey

指定 S3 身分驗證的秘密金鑰。

必要:有條件限制。只有在 type 屬性設為 S3 時,才能指定此項目。

類型:字串

type

指定身分驗證方案是否使用使用者名稱和密碼 (基本) 或存取金鑰 ID 和私密金鑰 (S3)。

若您指定 basic,請指定 usernamepassworduris 屬性。

若您指定 S3,請指定 accessKeyIdsecretKeybuckets (選擇性) 屬性。

必要:是

有效值basic | S3

uris

要和基本身分驗證憑證建立關聯的 URI 逗號分隔清單。授權會套用至指定的 URI 和任何更特定的 URI。例如,若您指定 http://www.example.com,授權也會套用至 http://www.example.com/test

必要:有條件限制。只有在 type 屬性設為 basic 時,才能指定此項目。

類型:字串值清單

username

指定基本身分驗證的使用者名稱。

必要:有條件限制。只有在 type 屬性設為 basic 時,才能指定此項目。

類型:字串

roleName

描述角色式身分驗證的角色。

重要

在連接至 EC2 執行個體的執行個體描述檔中,必須包含此角色。執行個體描述檔內只能有一個 IAM 角色。

必要:有條件限制。只有在 type 屬性設為 S3 時,才能指定此項目。

類型:字串

範例

注意

與大多數的資源不同,AWS::CloudFormation::Authentication 類型會定義一組使用者命名的區塊清單,其中每一項都包含使用小寫連字 (camel case) 命名的身分驗證屬性。

EC2 Web 伺服器身分驗證

此範本程式碼片段示範如何在 EC2 執行個體中從私有 S3 儲存貯體取得檔案。用於身分驗證的憑證是在 AWS::CloudFormation::Authentication 資源中定義,而且 AWS::CloudFormation::Init 資源會在檔案區段中參考它。

JSON

"WebServer": { "Type": "AWS::EC2::Instance", "DependsOn" : "BucketPolicy", "Metadata" : { "AWS::CloudFormation::Init" : { "config" : { "packages" : { "yum" : { "httpd" : [] } }, "files" : { "/var/www/html/index.html" : { "source" : { "Fn::Join" : [ "", [ "http://s3.amazonaws.com/", { "Ref" : "BucketName" }, "/index.html" ] ] }, "mode" : "000400", "owner" : "apache", "group" : "apache", "authentication" : "S3AccessCreds" } }, "services" : { "sysvinit" : { "httpd" : { "enabled" : "true", "ensureRunning" : "true" } } } } }, "AWS::CloudFormation::Authentication" : { "S3AccessCreds" : { "type" : "S3", "accessKeyId" : { "Ref" : "AccessKeyID" }, "secretKey" : { "Ref" : "SecretAccessKey" } } } }, "Properties": { EC2 Resource Properties ... } }

YAML

WebServer: Type: AWS::EC2::Instance DependsOn: BucketPolicy Metadata: AWS::CloudFormation::Init: config: packages: yum: httpd: [] files: /var/www/html/index.html: source: !Join - '' - - 'http://s3.amazonaws.com/' - !Ref BucketName - '/index.html' mode: '000400' owner: apache group: apache authentication: S3AccessCreds services: sysvinit: httpd: enabled: 'true' ensureRunning: 'true' AWS::CloudFormation::Authentication: S3AccessCreds: type: S3 accessKeyId: !Ref AccessKeyID secretKey: !Ref SecretAccessKey Properties: EC2 Resource Properties ...

指定基本和 S3 身分驗證

以下範例範本程式碼片段同時包含了基本S3 身分驗證類型。

JSON

"AWS::CloudFormation::Authentication" : { "testBasic" : { "type" : "basic", "username" : { "Ref" : "UserName" }, "password" : { "Ref" : "Password" }, "uris" : [ "example.com/test" ] }, "testS3" : { "type" : "S3", "accessKeyId" : { "Ref" : "AccessKeyID" }, "secretKey" : { "Ref" : "SecretAccessKey" }, "buckets" : [{ "Fn::Sub": "${BucketName}" }] } }

YAML

AWS::CloudFormation::Authentication: testBasic: type: basic username: !Ref UserName password: !Ref Password uris: - 'example.com/test' testS3: type: S3 accessKeyId: !Ref AccessKeyID secretKey: !Ref SecretAccessKey buckets: - !Sub ${BucketName}

IAM 角色

以下範例示範如何使用 IAM 角色:

  • myRoleAWS::IAM::Role 資源。

  • 執行 cfn-init 的 Amazon EC2 執行個體會透過執行個體描述檔與 myRole 建立關聯。

  • 範例會使用 buckets 屬性指定身分驗證,與 Amazon S3 身分驗證中的情況相同。您也可以使用名稱指定身分驗證。

JSON

"AWS::CloudFormation::Authentication": { "rolebased" : { "type": "S3", "buckets": [{ "Fn::Sub": "${BucketName}" }], "roleName": { "Ref": "myRole" } } }

YAML

AWS::CloudFormation::Authentication: rolebased: type: S3 buckets: - !Sub ${BucketName} roleName: !Ref myRole