AWS Verified Access エンドポイントで CloudFormation を使って ENI を指定してみた

2023.05.14

いわさです。

これまで Verified Access を使った検証を何度か行ってきました。
それらのプライベートアプリケーションではどれも Internal な Application Load Balancer を使っていました。

しかし Verified Access では Application Load Balancer 以外にも Network Load Balancer や Elastic Network Interface (ENI) もサポートされており、様々なマネージドサービスへの接続にも応用出来そうだと考えています。

そこで、本日は Verified Access から ENI への接続を行ってみましたので、構築方法を紹介します。
また、先日 Verified Access では CloudFormation がサポートされました。

こちらの紹介記事では Azure AD を信頼プロバイダーとして指定していましたが、テンプレートを使いまわししやすいように IAM Identity Center で今回構築しました。

まず、テンプレートの全体は以下のリポジトリにプッシュしています。この記事ではポイントの抜粋のみを行っていますので、テンプレート全体を確認したい方はこちらからどうぞ。

このテンプレートでは以下のような構成一式をデプロイ出来ます。(Identity Center と Route 53 ホストゾーンは対象外)

IAM Identity Center を使った CloudFormation

IAM Identity Center の指定はAWS::EC2::VerifiedAccessTrustProviderで行います。
次のようにUserTrustProviderTypeiam-identity-centerを指定するだけです。

:
  #######################
  # Verified Access
  #######################
  HogeInstance:
    Type: AWS::EC2::VerifiedAccessInstance
    Properties: 
      VerifiedAccessTrustProviderIds: 
        - !Ref HogeTrustProvider

  HogeTrustProvider:
    Type: AWS::EC2::VerifiedAccessTrustProvider
    Properties: 
      PolicyReferenceName: !Sub ${AWS::StackName}policy
      TrustProviderType: user
      UserTrustProviderType: iam-identity-center
:

Azure AD を信頼プロバイダーとする場合は OIDC のプロパティを色々と設定しつつ、最後にリダイレクト URI を Azure AD 側にも設定する必要があったのですが、IAM Identity Center の場合はこれだけで終わりです。

Verified Access のターゲットに ENI を指定する

次は本題の ENI 指定部分です。
次のようにエンドポイントタイプにnetwork-interfaceを指定し、NetworkInterfaceOptionsにはターゲットの ENI とプロトコル・ポートを指定しています。
他は ALB の場合と同じです。

:
  HogeEndpoint:
    Type: AWS::EC2::VerifiedAccessEndpoint
    Properties: 
      ApplicationDomain: !Ref ApplicationDomain
      AttachmentType: vpc
      DomainCertificateArn: !Ref Certificate
      EndpointDomainPrefix: !Sub ${AWS::StackName}
      EndpointType: network-interface
      NetworkInterfaceOptions:
        NetworkInterfaceId: !Ref MyNetworkInterface
        Port: 80
        Protocol: http
      SecurityGroupIds:
        - !Ref HogeSecurityGroup
      VerifiedAccessGroupId: !Ref HogeGroup
:

作成したリソース

テンプレートをデプロイすると 10 ~ 15 分程度でデプロイが完了します。

% rain deploy template.yaml hoge0513 -r us-east-1 -p hogeadmin
Deleted existing, empty stack.
Enter a value for parameter 'ApplicationDomain' (existing value: hoge0513.fuga.tak1wa.com): 
Enter a value for parameter 'HostZoneId' (existing value: Z05132602TL6PL61SUQV2): 
Enter a value for parameter 'BaseAMI' (existing value: /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2): 
CloudFormation will make the following changes:
Stack hoge0513:
  + AWS::EC2::VPCGatewayAttachment AttachGateway
  + AWS::CertificateManager::Certificate Certificate
  + AWS::Route53::RecordSet DnsWebRecord
  + AWS::EC2::EIP EipNatGateway1
  + AWS::EC2::VerifiedAccessEndpoint HogeEndpoint
  + AWS::EC2::VerifiedAccessGroup HogeGroup
  + AWS::EC2::VerifiedAccessInstance HogeInstance
  + AWS::EC2::SecurityGroup HogeSecurityGroup
  + AWS::EC2::VerifiedAccessTrustProvider HogeTrustProvider
  + AWS::EC2::InternetGateway InternetGateway
  + AWS::EC2::NetworkInterface MyNetworkInterface
  + AWS::EC2::NatGateway NatGateway1
  + AWS::EC2::Route ProtectedRoute1
  + AWS::EC2::RouteTable ProtectedRouteTable1
  + AWS::EC2::SubnetRouteTableAssociation ProtectedSubnet1RouteTableAssociation
  + AWS::EC2::Subnet ProtectedSubnet1
  + AWS::EC2::RouteTable PublicRouteTable
  + AWS::EC2::Route PublicRoute
  + AWS::EC2::SubnetRouteTableAssociation PublicSubnet1RouteTableAssociation
  + AWS::EC2::Subnet PublicSubnet1
  + AWS::EC2::VPC VPC
  + AWS::IAM::InstanceProfile WebProfile
  + AWS::IAM::Role WebRole
  + AWS::EC2::SecurityGroup WebServerSecurityGroup
  + AWS::EC2::Instance WebServer
Do you wish to continue? (Y/n) 
Deploying template 'template.yaml' as stack 'hoge0513' in us-east-1.
Stack hoge0513: ROLLBACK_COMPLETE
failed deploying stack 'hoge0513'
iwasa.takahito@HL01200 hoge0513verified % rain deploy template.yaml hoge0513 -r us-east-1 -p hogeadmin -y
Deleted existing, empty stack.
Deploying template 'template.yaml' as stack 'hoge0513' in us-east-1.
Stack hoge0513: CREATE_COMPLETE
Successfully deployed hoge0513

アプリケーションドメインにアクセスすると IAM Identit Center のサインインが要求され、認証されるとプライベートアプリケーションへアクセスすることが出来ます。

Verified Access エンドポイントが ENI 用に構成される

今回 CloudFormation で構築していますが、もちろんマネジメントコンソールからも構築が可能です。
その場合は次のように Verified Access エンドポイントで ENI のエンドポイントタイプを構成するだけです。

Verified Access エンドポイントで ENI が自動生成される

エンドポイント構成でターゲットの ENI を指定しましたが、これはリクエストの送信先です。
Verified Access が使う ENI は独自に生成してアタッチはできず、Verified Access エンドポイントの作成時に自動作成されます。

なお、この時に作成されるサブネットはプライベートアプリケーションの ENI と同じサブネットです。

さいごに

本日は AWS Verified Access エンドポイントで CloudFormation を使って ENI を指定してみました。

これがおそらく Verified Access を含む CloudFormation 一式のリソース数としては最小の構成になるのではないでしょうか。
ALB だとターゲットに指定出来るもののみが対象でしたが、ENI が扱えるようになるとプライベート IP アドレスが割り振られる大抵のものには HTTP/HTTPS アクセス出来るようになりそうです。