目次
AWS CodeArtifact 完全ガイド v2.0 (2026 年最新対応)
マネージドアーティファクト・パッケージリポジトリサービス完全実装ガイド
概要
AWS CodeArtifact は 「npm・PyPI・Maven・NuGet・Cargo・Swift などの多言語パッケージマネージャー対応のフルマネージドアーティファクトリポジトリサービス。社内パッケージの公開・プライベート依存関係の管理・外部レジストリ(npmjs.com・PyPI)のキャッシング・Dependency Confusion 攻撃対策を一元化」 します。
2025-2026 の最新機能:
- Dependency Origin Controls:Dependency Confusion 攻撃を完全ブロック
- Pull-Through Cache Metrics:キャッシュヒット率・帯域使用量を可視化
- Upstream Repository Chaining:リポジトリの階層化・段階的パッケージ承認
- Package Origin Allowlist:セキュリティチームが承認したパッケージのみ許可
1. 課題と特徴
CodeArtifact が解決する課題
❌ 課題 1:社内パッケージの共有が複雑
→ Artifactory・Nexus 導入 → インフラ運用コスト・スケーリング課題
→ npm・pip・maven それぞれ別環境
→ バージョン管理・アクセス制御が煩雑
✅ 解決:CodeArtifact
→ フルマネージド・AWS IAM 統合・スケーリング自動
→ npm・pip・maven・NuGet・Cargo・Swift 一元管理
→ ドメイン・リポジトリ階層化で段階的パッケージ승인
→ 月額 $0.05/GB storage + $0.05/10,000 requests
❌ 課題 2:Dependency Confusion 攻撃のリスク
→ ci/cd で npmjs.com・pypi.org から直接インストール
→ 悪意のあるパッケージが同名で publish → 自動インストール
→ 社内ライブラリ盗聴・マルウェア混入・supply chain 攻撃
✅ 解決:CodeArtifact のセキュリティ機能
→ Package Origin Controls:internal + external from separate sources
→ Dependency Allowlist:承認済みパッケージのみ許可
→ Pull-Through Cache:公開レジストリは codearifact 経由のみ
→ VPC endpoint:インターネット不要・プライベートアクセス
❌ 課題 3:CI/CD ビルドの遅さ
→ npm install で npmjs.com にアクセス → ネットワーク latency
→ パッケージダウンロード遅い → ビルド 3 分 → 無駄
✅ 解決:CodeArtifact Pull-Through Cache
→ 初回:npmjs.com から取得・キャッシュ
→ 2 回目以降:codearifact から高速配信(同一 region → <100ms)
→ ビルド時間 30% 短縮
コアの特徴
| 特徴 | 説明 |
|---|---|
| 多言語対応 | npm・PyPI・Maven・NuGet・Cargo・Swift・Generic |
| フルマネージド | インフラ管理・スケーリング・バージョン管理自動 |
| ドメイン・リポジトリ階層 | Org レベル domain → project 毎 repository |
| Pull-Through Cache | 外部レジストリを透過的にキャッシュ |
| Upstream Repository | リポジトリ間で package access chain 設定 |
| Dependency Origin Controls | Dependency Confusion 攻撃対策・package source 制御 |
| AWS IAM 統合 | resource ベース権限・fine-grained access control |
| VPC Endpoint | インターネット不要・プライベートアクセス |
| Encryption | 保存時 KMS・転送時 TLS |
| Retention Policy | package 自動削除・lifecycle management |
2. アーキテクチャ(Mermaid 図 1)
graph LR
A["Developer<br/>npm install / pip install"] -->|Query| B["CodeArtifact<br/>Repository"]
B -->|Check cache| C{"Package<br/>in Cache?"}
C -->|Yes| D["Return from<br/>CodeArtifact<br/>(<100ms)"]
C -->|No| E["Fetch from<br/>Upstream<br/>npmjs.com/PyPI"]
E -->|Cache| F["Store in<br/>CodeArtifact<br/>S3 Backend"]
F -->|Return| D
D -->|Package| G["CI/CD Build<br/>CodeBuild"]
G -->|Build Output| H["ECR / S3<br/>Artifact"]
I["CodeArtifact Domain<br/>(Organization Unit)"] -->|Contains| J["Repository A<br/>(dev)"]
I -->|Contains| K["Repository B<br/>(stg)"]
I -->|Contains| L["Repository C<br/>(prod)"]
J -->|Upstream→| K
K -->|Upstream→| L
M["AWS IAM"] -->|Control Access| B
N["Secrets Manager"] -->|Credentials| A
O["CloudTrail"] -->|Audit Log| B
style B fill:#fff3cd
style D fill:#d1ecf1
style E fill:#f8f9fa
style F fill:#d4edda
style I fill:#cfe2ff
style M fill:#fce4ec
3. コアコンポーネント
3.1 ドメイン・リポジトリ構造
# CodeArtifact Domain(org 単位)
Domain:
Name: my-org-artifacts
Description: "Central artifact repository for my-org"
Owner: 123456789012
RepositoryCount: 3
StorageQuota: 1000 # GB
# Repository(project/team 単位)
Repositories:
# 1. Dev Repository(全パッケージ許可・快速)
- Name: dev-repo
Domain: my-org-artifacts
Type: NPM
ExternalConnections:
- npmjs.com(public repo)
UpstreamRepositories: []
DefaultBranch: ""
Description: "Development - all packages allowed"
S3BucketArn: arn:aws:s3:::artifact-dev-bucket
# 2. Staging Repository(承認済みパッケージ)
- Name: stg-repo
Domain: my-org-artifacts
Type: NPM
ExternalConnections: []
UpstreamRepositories:
- dev-repo # dev-repo から패키지 상속
Description: "Staging - security-approved packages only"
# 3. Production Repository(最厳格)
- Name: prod-repo
Domain: my-org-artifacts
Type: NPM
ExternalConnections: []
UpstreamRepositories:
- stg-repo # stg-repo から只 승인済み継承
DependencyOriginConfiguration:
Restrictions: PUBLISH # 직접 publish 禁止
Description: "Production - restricted to approved versions"
# パッケージフロー
PackageFlow:
"npmjs.com"
→ dev-repo (Pull-Through Cache)
→ stg-repo (Security Review)
→ prod-repo (Restricted Release)
3.2 外部接続(Pull-Through Cache)
# Pull-Through Cache 設定
ExternalConnection:
Repository: dev-repo
RepositoryType: NPM
ExternalRepositoryUrl: https://registry.npmjs.org
PackageFormat: npm
# または PyPI
ExternalConnection:
Repository: python-repo
RepositoryType: PYPI
ExternalRepositoryUrl: https://pypi.org
# または Maven Central
ExternalConnection:
Repository: java-repo
RepositoryType: MAVEN
ExternalRepositoryUrl: https://repo.maven.apache.org/maven2
# または NuGet
ExternalConnection:
Repository: dotnet-repo
RepositoryType: NUGET
ExternalRepositoryUrl: https://api.nuget.org/v3/index.json
# 動作フロー
1. npm install axios
2. CodeArtifact が dev-repo をチェック
3. キャッシュなし → npmjs.com から fetch
4. CodeArtifact に cache → 次回は高速配信
5. 同一 region:<100ms、別 region:~500ms
# キャッシュ統計
CacheMetrics:
TotalRequests: 10000
CacheHits: 8500 # 85% hit rate
CacheMisses: 1500
AverageFetchTime: 250ms
BandwidthSaved: 50GB/month
3.3 Dependency Origin Controls(セキュリティ)
# Dependency Confusion Attack Prevention
# Before(脆弱)
- Repository: dev-repo
ExternalConnection: npmjs.com
npm install @company/utils
# 攻撃者が npmjs.com に @company/utils publish
→ npm install @company/utils → 悪意版インストール ❌
# After(CodeArtifact)
- Repository: dev-repo
DependencyOriginConfiguration:
Restrictions: PUBLISH # internal only publish
- Repository: stg-repo
DependencyOriginConfiguration:
Restrictions: UPSTREAM # upstream repo からのみ可
npm install @company/utils
→ stg-repo チェック → dev-repo チェック → npmjs.com か internal か判定
→ internal のみアクセス許可 → 攻撃防止 ✅
# 詳細設定
RestrictedRepositories:
- Name: prod-repo
AllowPublishThrough:
- INTERNAL_REPOSITORY # 内部 repo からのみ publish
AllowUpstreamPublish: false
BlockExternalPublish: true # 外部 registry からの publish 禁止
- Name: stg-repo
AllowPublishThrough:
- INTERNAL_REPOSITORY
AllowUpstreamPublish: true # upstream (dev) から publish 継承
BlockExternalPublish: true
- Name: dev-repo
AllowPublishThrough:
- INTERNAL_REPOSITORY
AllowUpstreamPublish: false
BlockExternalPublish: false # 外部registry も許可(開発用)
3.4 パッケージ承認フロー
# Security Team が承認したパッケージのみ prod へ流す
SecurityApprovalFlow:
Stage1_DevelopmentRepo:
Description: "All packages - dev team freedom"
Action:
- npm install # 制限なし
- Test & development
Stage2_SecurityReview:
Description: "Security team reviews"
Action:
- SAST scan(npm audit)
- License check(SPDX)
- Vulnerability scan(Snyk)
- Manual approval
- Promote to stg-repo
Stage3_StagingRepo:
Description: "Approved packages only"
Action:
- Integration test
- Performance test
- Load test
Stage4_ProductionRepo:
Description: "Restricted to prod deploys"
Action:
- Manual sign-off
- Production deploy only
# 手順
1. dev-repo に @company/utils@1.2.3 publish
2. Security team が npm audit run → OK
3. Security team が stg-repo に promote
4. stg で integration test → OK
5. Security team が prod-repo に promote
6. Production deploy で @company/utils@1.2.3 使用可能
4. 主要ユースケース(12+)
4.1 多言語社内パッケージ共有
# 一つの CodeArtifact Domain で複数言語管理
Domain: my-org-artifacts
Repositories:
- Name: npm-repo
Type: NPM
Description: "Node.js packages"
- Name: python-repo
Type: PYPI
Description: "Python packages"
- Name: java-repo
Type: MAVEN
Description: "Java libraries"
- Name: dotnet-repo
Type: NUGET
Description: ".NET packages"
# 各 team が言語別 repo を使用
Frontend Team: npm-repo → @company/ui-components
Backend Team: java-repo → com.company:utils
Python Team: python-repo → company-utils
.NET Team: dotnet-repo → Company.Utils
4.2 npm パッケージの社内公開・共有
# 1. @company scope で internal npm package 作成
# package.json
{
"name": "@company/shared-utils",
"version": "1.0.0",
"description": "Shared utilities for all projects",
"main": "dist/index.js"
}
# 2. CodeArtifact に publish
aws codeartifact login --tool npm \
--repository npm-repo \
--domain my-org-artifacts \
--domain-owner 123456789012
npm publish
# 3. 他プロジェクトで install
npm install @company/shared-utils
# 4. Version bump & republish
npm version minor
npm publish
# 5. Downstream projects automatically fetch new version
npm update @company/shared-utils
4.3 Python ライブラリ共有
# 1. setup.py
from setuptools import setup
setup(
name="company-utils",
version="1.0.0",
description="Shared Python utilities",
packages=find_packages(),
)
# 2. CodeArtifact に publish
aws codeartifact login --tool pip \
--repository python-repo \
--domain my-org-artifacts
python -m twine upload dist/*
# 3. 他プロジェクトで install
pip install company-utils
# 4. requirements.txt
company-utils>=1.0.0
4.4 Maven 社内ライブラリ管理
# 1. pom.xml
<groupId>com.company</groupId>
<artifactId>shared-utils</artifactId>
<version>1.0.0</version>
# 2. settings.xml(CodeArtifact)
<servers>
<server>
<id>codeartifact</id>
<username>aws</username>
<password>$(aws codeartifact get-authorization-token ...)</password>
</server>
</servers>
<repository>
<id>codeartifact</id>
<url>https://my-domain-123456789012.d.codeartifact.us-east-1.amazonaws.com/maven/java-repo/</url>
</repository>
# 3. Deploy
mvn deploy
# 4. 他プロジェクト pom.xml
<dependency>
<groupId>com.company</groupId>
<artifactId>shared-utils</artifactId>
<version>1.0.0</version>
</dependency>
mvn install # → CodeArtifact から自動取得
4.5 Pull-Through Cache で npm 高速化
CI/CD Pipeline(CodeBuild)
npm install (100 パッケージ)
Before CodeArtifact:
- npmjs.com から download:3 分
- ネットワーク latency・throttle で遅延
- 全体ビルド:10 分
After CodeArtifact:
- 初回:npmjs → CodeArtifact cache (3 分)
- 2 回目以降:CodeArtifact から高速 (<100ms per package)
- 全体ビルド:7 分(30% 短縮)
- 月 500 builds → 月 250 分削減 = $30 節約(CodeBuild 課金)
4.6 Dependency Confusion 対策
# 攻撃シナリオを完全ブロック
Scenario:
Company: Acme Corp
Internal Package: @acme/payment-sdk
Attack:
1. Hacker が npmjs.com に @acme/payment-sdk publish
2. Version: 999.0.0 (高い version番号)
3. npm install @acme/payment-sdk → npm が highest version fetch
4. 悪意版 @acme/payment-sdk インストール ❌
CodeArtifact Defense:
Repository: acme-prod
DependencyOriginConfiguration:
Restrictions: PUBLISH # internal repo only publish
npm install @acme/payment-sdk
→ acme-prod が @acme/payment-sdk を検索
→ 内部 repo (acme-dev) からのみアクセス許可
→ npmjs.com はブロック
→ 悪意版は install されない ✅
4.7 UpstreamRepository で段階的承認
# 3 段階リポジトリ構成
dev-repo (upstream=none, external-connection=npmjs)
↑
└─→ stg-repo (upstream=dev-repo, no external-connection)
↑
└─→ prod-repo (upstream=stg-repo, no external-connection, restricted)
Package Lifecycle:
1. Developer が dev-repo に publish
npm publish
→ dev-repo に @company/utils@1.2.3 登録
2. npm install @company/utils@1.2.3
→ dev-repo 検索 → hit → install ✅
3. Security review & approve
→ @company/utils@1.2.3 を stg-repo に move/copy
4. npm install @company/utils@1.2.3 in staging
→ stg-repo 検索 → hit → install ✅
5. Production readiness approved
→ @company/utils@1.2.3 を prod-repo に move/copy
6. npm install @company/utils@1.2.3 in production
→ prod-repo 検索 → hit → install ✅
→ dev-repo の unstable 版は prod install 不可能 ✅
4.8 Cross-Account リポジトリアクセス
# Account A(package owner)から Account B(consumer)へ公開
Account A:
Domain: org-artifacts
Repository: shared-lib
IAM Policy:
Principal: arn:aws:iam::ACCOUNT_B:root
Action: codeartifact:GetAuthorizationToken
Resource: arn:aws:codeartifact:*:ACCOUNT_A:domain/org-artifacts
Account B:
npm config set registry https://org-artifacts-ACCOUNT_A.d.codeartifact.REGION.amazonaws.com/npm/shared-lib/
npm login --registry https://...
npm install @org/shared-lib
4.9 VPC Endpoint で internet 不要
# プライベート VPC から CodeArtifact へセキュアアクセス
VPC Endpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
ServiceName: com.amazonaws.REGION.codeartifact
VpcId: vpc-12345678
SubnetIds: [subnet-private-1, subnet-private-2]
SecurityGroupIds: [sg-codeartifact]
PrivateDnsEnabled: true
# CodeBuild(VPC 内)
BuildSpec:
phases:
install:
commands:
# インターネット不要・VPC endpoint 経由
- npm install # → CodeArtifact VPC endpoint → package download
- pip install # → CodeArtifact VPC endpoint → package download
4.10 License Compliance チェック
# npm-cli-login で認証
npm login --registry https://my-domain.d.codeartifact.REGION.amazonaws.com/npm/repo/
# license check
npm audit # → CodeArtifact package の license 確認
# or external tool
npx license-checker
# → Apache 2.0, MIT, BSD: OK
# → GPL, AGPL: Alert
4.11 自動削除ポリシー(cost 最適化)
# 古いバージョンの自動削除
RetentionConfiguration:
Repository: dev-repo
Rules:
- PackagePattern: "@company/*"
MaxVersionCount: 5 # 最新 5 バージョンのみ保持
Action: DELETE
- PackagePattern: "test-*"
DaysToRetain: 7 # 7 日以上前は削除
Action: DELETE
- PackagePattern: "@production/*"
DaysToRetain: 90 # 本番は 90 日保持
Action: DELETE
# コスト削減
Before: 100 versions × 50MB = 5GB storage cost
After: 5 versions × 50MB = 250MB storage cost
→ 95% 削減
4.12 監査ログ・権限制御
# CloudTrail で全操作監査
CloudTrail Events:
- GetPackageVersion
- PublishPackageVersion
- UpdatePackageVersionsStatus
- DeletePackageVersion
- PutRepositoryPermissionsPolicy
# IAM ベース権限制御
Policy:
Effect: Allow
Action:
- codeartifact:ReadFromRepository # install
- codeartifact:GetAuthorizationToken
Resource:
- arn:aws:codeartifact:*:*:package/domain/repo/format/package-name
Condition:
StringEquals:
'codeartifact:DomainOwnerAccount': '123456789012'
# dev-repo には full access、prod-repo には read-only
Action:
- codeartifact:PublishPackageVersion # dev-repo
- codeartifact:ReadFromRepository # prod-repo (read-only)
5. 設定・操作の具体例
5.1 CLI で Domain・Repository 作成
# 1. Domain 作成
aws codeartifact create-domain \
--domain my-org-artifacts \
--domain-owner 123456789012 \
--encryption-key arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012
# 2. NPM Repository 作成
aws codeartifact create-repository \
--domain my-org-artifacts \
--domain-owner 123456789012 \
--repository dev-repo \
--description "Development npm repository"
# 3. External Connection(Pull-Through Cache)設定
aws codeartifact associate-external-connection \
--domain my-org-artifacts \
--domain-owner 123456789012 \
--repository dev-repo \
--external-connection "public:npmjs"
# 4. npm login
aws codeartifact login \
--tool npm \
--domain my-org-artifacts \
--domain-owner 123456789012 \
--repository dev-repo \
--region us-east-1
# 5. npm publish
npm publish
# 6. 他リポジトリ設定(upstream)
aws codeartifact create-repository \
--domain my-org-artifacts \
--repository stg-repo \
--upstreams repositoryName=dev-repo
# 7. Dependency Origin Controls
aws codeartifact put-repository-permissions-policy \
--domain my-org-artifacts \
--repository prod-repo \
--policy-document file://policy.json
# policy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "codeartifact:ReadFromRepository",
"Resource": "arn:aws:codeartifact:*:*:package/domain/prod-repo/*"
}
]
}
# 8. 認可トークン取得(API 直接アクセス)
aws codeartifact get-authorization-token \
--domain my-org-artifacts \
--domain-owner 123456789012 \
--query authorizationToken \
--output text
5.2 CloudFormation で Domain・Repository 定義
# codeartifact-setup.yaml
AWSTemplateFormatVersion: '2010-09-09'
Resources:
CodeArtifactDomain:
Type: AWS::CodeArtifact::Domain
Properties:
DomainName: my-org-artifacts
EncryptionKey: !GetAtt KMSKey.Arn
KMSKey:
Type: AWS::KMS::Key
Properties:
Description: "KMS key for CodeArtifact encryption"
KeyPolicy:
Version: '2012-10-17'
Statement:
- Sid: Enable IAM policies
Effect: Allow
Principal:
AWS: !Sub 'arn:aws:iam::${AWS::AccountId}:root'
Action: 'kms:*'
Resource: '*'
DevRepository:
Type: AWS::CodeArtifact::Repository
Properties:
DomainName: !Ref CodeArtifactDomain
RepositoryName: dev-repo
Description: "Development repository with external npm connection"
ExternalConnections:
- public:npmjs
RepositoryType: NPM
StagingRepository:
Type: AWS::CodeArtifact::Repository
Properties:
DomainName: !Ref CodeArtifactDomain
RepositoryName: stg-repo
Description: "Staging repository (upstream: dev-repo)"
RepositoryType: NPM
Upstreams:
- RepositoryName: !GetAtt DevRepository.RepositoryName
ProductionRepository:
Type: AWS::CodeArtifact::Repository
Properties:
DomainName: !Ref CodeArtifactDomain
RepositoryName: prod-repo
Description: "Production repository (restricted, upstream: stg-repo)"
RepositoryType: NPM
Upstreams:
- RepositoryName: !GetAtt StagingRepository.RepositoryName
Outputs:
DomainName:
Value: !GetAtt CodeArtifactDomain.DomainName
RepositoryEndpoint:
Value: !Sub 'https://${CodeArtifactDomain}.d.codeartifact.${AWS::Region}.amazonaws.com/npm/${DevRepository}/'
5.3 CDK で Domain・Repository 定義
import * as cdk from 'aws-cdk-lib';
import * as codeartifact from 'aws-cdk-lib/aws-codeartifact';
import * as kms from 'aws-cdk-lib/aws-kms';
export class CodeArtifactStack extends cdk.Stack {
constructor(scope: cdk.App, id: string) {
super(scope, id);
// KMS Key for encryption
const kmsKey = new kms.Key(this, 'CodeArtifactKey', {
description: 'KMS key for CodeArtifact',
removalPolicy: cdk.RemovalPolicy.RETAIN,
});
// CodeArtifact Domain
const domain = new codeartifact.Domain(this, 'Domain', {
domainName: 'my-org-artifacts',
encryptionKey: kmsKey,
});
// Dev Repository with external npm connection
const devRepo = new codeartifact.Repository(this, 'DevRepo', {
domain: domain,
repositoryName: 'dev-repo',
description: 'Development - all packages allowed',
externalConnections: ['public:npmjs'],
});
// Staging Repository with upstream: dev-repo
const stgRepo = new codeartifact.Repository(this, 'StgRepo', {
domain: domain,
repositoryName: 'stg-repo',
description: 'Staging - approved packages',
upstreams: [devRepo],
});
// Production Repository with upstream: stg-repo
const prodRepo = new codeartifact.Repository(this, 'ProdRepo', {
domain: domain,
repositoryName: 'prod-repo',
description: 'Production - restricted',
upstreams: [stgRepo],
});
// Output
new cdk.CfnOutput(this, 'DevRepoEndpoint', {
value: `https://${domain.domainName}.d.codeartifact.${this.region}.amazonaws.com/npm/dev-repo/`,
});
}
}
6. 類似サービス比較表
| 機能 | CodeArtifact | JFrog Artifactory | Nexus Repository | GitHub Packages | GCP Artifact Registry | Azure Artifacts |
|---|---|---|---|---|---|---|
| 多言語対応 | ✅ npm/pip/maven/nuget/cargo | ✅ 全対応 | ✅ 全対応 | △ GitHub native | ✅ 全対応 | ✅ 全対応 |
| フルマネージド | ✅ AWS managed | △ SaaS/Self-hosted | △ Self-hosted | ✅ GitHub managed | ✅ GCP managed | ✅ Azure managed |
| Pull-Through Cache | ✅ 標準 | ✅ Smart Remote Repos | △ Proxy repos | △ Package registry | ✅ Remote repos | △ |
| Dependency Confusion対策 | ✅ Origin controls (2025) | ✅ Realms | △ Limited | △ Limited | △ | △ |
| VPC/Private | ✅ VPC endpoint | △ On-Prem | ✅ On-Prem | ✅ Private Networking | ✅ Private service | ✅ |
| AWS IAM統合 | ✅ Native | △ 連携可能 | △ Plugin | △ | ✅ Service Account | △ |
| Cost | `0.05/GB + requests | `3-7K/month | Self-hosted | Free + overages | $0.25/GB | Variable |
| 推奨対象 | AWS-native | Enterprise complex | Enterprise | GitHub users | GCP users | Azure users |
7. ベストプラクティス(✅/❌)
✅ すべき設定
| 項目 | 実装例 | 理由 |
|---|---|---|
| 3 段階リポジトリ | dev → stg → prod | Dependency Confusion 対策・段階的承認 |
| upstream設定 | prod-repo (upstream=stg) | package flow control・single source |
| External Connection | dev-repo only | security・pull-through cache |
| Origin Controls | PUBLISH restriction | internal package 保護 |
| VPC Endpoint | private access | インターネット不要・セキュア |
| Retention Policy | 古版自動削除 | storage cost 削減 |
| IAM最小権限 | read-only prod-repo | アクセス制御・accident prevention |
| KMS暗号化 | domain-level encryption | compliance・data protection |
❌ アンチパターン
| 項目 | 問題 | 改善案 |
|---|---|---|
| 単一リポジトリ | 開発・本番混在 | 3 段階化・upstream 設定 |
| 全リポジトリで external connection | Dependency Confusion リスク | dev-repo のみ external |
| 全員に publish 権限 | 誤版本・悪意 publish | IAM 最小権限・approval workflow |
| retention 無制限 | storage cost 爆増 | lifecycle policy 設定 |
| 監査ログなし | compliance 未対応 | CloudTrail 有効化 |
| 認証なし public access | セキュリティ漏洞 | IAM policy・VPC endpoint |
| Dependency Confusion 対策なし | supply chain attack | Origin Controls・upstream chain |
8. トラブルシューティング表
| 症状 | 原因 | 解決方法 |
|---|---|---|
| npm install 403 Forbidden | IAM 権限不足 | codeartifact:ReadFromRepository 追加・token refresh |
| npm publish 401 Unauthorized | 認証トークン期限切れ | aws codeartifact login 再実行 |
| Pull-through cache hit なし | external connection 未設定 | associate-external-connection with public:npmjs |
| 古いパッケージ版が install | Retention policy 不正 | 対象バージョン確認・lifecycle rule review |
| Cross-account access 失敗 | principal policy 不正 | target account IAM trust policy 確認 |
| VPC endpoint 経由アクセス失敗 | DNS resolution 失敗 | PrivateDnsEnabled=true・security group check |
| Dependency Confusion detected | external connection open | Origin Controls 設定・repository 分離 |
| Package metadata 取得遅い | キャッシュミス多い | pull-through cache warmup・external repo health check |
9. 2025-2026 最新動向
9.1 Dependency Origin Controls の GA
2025 年初に Dependency Confusion 完全対策機能が GA。Package origin allowlist・external publish block・upstream-only configuration で、supply chain attack を根本的に防止。
9.2 Pull-Through Cache Metrics の実装
キャッシュヒット率・fetch latency・bandwidth savings が dashboard に可視化。cost optimization decision を data-driven で実施可能に。
9.3 Package Retention AI
古いバージョンの自動削除を AI で最適化。usage patterns を学習し、必要な版数を予測。
9.4 Cargo(Rust)・Swift 対応拡大
2026 年に Cargo・Swift package manager も GA。マイクロサービス・embedded system development の package 管理が統一可能に。
10. 学習リソース・参考文献
公式ドキュメント(8+)
- AWS CodeArtifact User Guide
- CodeArtifact Concepts
- External Connection Setup
- Dependency Origin Controls
- Upstream Repositories
- VPC Endpoints for CodeArtifact
- Authentication with Tokens
- CodeArtifact Pricing
オープンソース・参考実装(5+)
- aws-samples/aws-codeartifact-samples - 多言語 setup
- npm-cli-login - npm authentication
- JFrog Artifactory Documentation - Artifactory 比較参考
- Sonatype Nexus Repository - Nexus 比較参考
- Dependency Confusion Research - セキュリティ脅威分析
参考記事(2025-2026)
- Dependency caching in AWS CodeArtifact
- Dependency confusion in AWS CodeArtifact - Zego Engineering
- How to Set Up AWS CodeArtifact for Package Management - Oneuptime 2026
11. 実装例:エンタープライズ 3 段階 Approval Flow
# codeartifact-3-stage-approval.yaml
AWSTemplateFormatVersion: '2010-09-09'
Resources:
CodeArtifactDomain:
Type: AWS::CodeArtifact::Domain
Properties:
DomainName: enterprise-artifacts
EncryptionKey: !Ref KMSKey
# Stage 1: Development(自由・外部接続あり)
DevRepository:
Type: AWS::CodeArtifact::Repository
Properties:
DomainName: !Ref CodeArtifactDomain
RepositoryName: dev-repo
Description: "Development - all packages, external npm connection"
ExternalConnections:
- public:npmjs
- public:pypi
# Stage 2: Staging(upstream: dev、internal only)
StagingRepository:
Type: AWS::CodeArtifact::Repository
Properties:
DomainName: !Ref CodeArtifactDomain
RepositoryName: stg-repo
Description: "Staging - security reviewed"
Upstreams:
- RepositoryName: !GetAtt DevRepository.RepositoryName
# Stage 3: Production(upstream: stg、最厳格)
ProductionRepository:
Type: AWS::CodeArtifact::Repository
Properties:
DomainName: !Ref CodeArtifactDomain
RepositoryName: prod-repo
Description: "Production - approved only"
Upstreams:
- RepositoryName: !GetAtt StagingRepository.RepositoryName
# IAM Role: Developer(dev-repo: publish, stg/prod: read)
DeveloperRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
AWS: !Sub 'arn:aws:iam::${AWS::AccountId}:group/developers'
Action: sts:AssumeRole
Policies:
- PolicyName: CodeArtifactDeveloper
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- codeartifact:PublishPackageVersion
- codeartifact:ReadFromRepository
Resource: !Sub 'arn:aws:codeartifact:${AWS::Region}:${AWS::AccountId}:package/enterprise-artifacts/dev-repo/*'
- Effect: Allow
Action:
- codeartifact:ReadFromRepository
Resource:
- !Sub 'arn:aws:codeartifact:${AWS::Region}:${AWS::AccountId}:package/enterprise-artifacts/stg-repo/*'
- !Sub 'arn:aws:codeartifact:${AWS::Region}:${AWS::AccountId}:package/enterprise-artifacts/prod-repo/*'
- Effect: Allow
Action:
- codeartifact:GetAuthorizationToken
Resource: !Sub 'arn:aws:codeartifact:${AWS::Region}:${AWS::AccountId}:domain/enterprise-artifacts'
# IAM Role: Security Team(all read + promote)
SecurityRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
AWS: !Sub 'arn:aws:iam::${AWS::AccountId}:group/security-team'
Action: sts:AssumeRole
Policies:
- PolicyName: CodeArtifactSecurityReview
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- codeartifact:ReadFromRepository
- codeartifact:UpdatePackageVersionsStatus
Resource: !Sub 'arn:aws:codeartifact:${AWS::Region}:${AWS::AccountId}:package/enterprise-artifacts/*'
- Effect: Allow
Action:
- codeartifact:GetAuthorizationToken
Resource: !Sub 'arn:aws:codeartifact:${AWS::Region}:${AWS::AccountId}:domain/enterprise-artifacts'
Outputs:
DevRepositoryEndpoint:
Value: !Sub 'https://enterprise-artifacts-${AWS::AccountId}.d.codeartifact.${AWS::Region}.amazonaws.com/npm/dev-repo/'
StagingRepositoryEndpoint:
Value: !Sub 'https://enterprise-artifacts-${AWS::AccountId}.d.codeartifact.${AWS::Region}.amazonaws.com/npm/stg-repo/'
ProductionRepositoryEndpoint:
Value: !Sub 'https://enterprise-artifacts-${AWS::AccountId}.d.codeartifact.${AWS::Region}.amazonaws.com/npm/prod-repo/'
12. 導入ロードマップ
Week 1: 計画・IAM 設定
├── Domain 要件定義(3-stage vs single)
├── Repository 設計(npm/python/maven etc)
├── IAM role・policy 設計
└── KMS key 作成
Week 2: Domain・Repository 構築
├── CodeArtifact Domain 作成
├── Repository 3 つ作成
├── External connection 設定(dev)
└── Upstream repository 設定
Week 3: 認証・テスト
├── npm/pip login test
├── publish test(dev-repo)
├── install test(stg/prod)
└── upstream access 確認
Week 4: CI/CD 統合
├── CodeBuild buildspec.yml 修正
├── CodePipeline artifact stage 修正
├── Promotion workflow 実装
└── 監査ログ設定
Week 5+: 本番運用
├── Team training
├── 社内ライブラ리マイグレーション
├── Retention policy 設定
└── Cost monitoring
13. チェックリスト
構成チェックリスト
- [ ] CodeArtifact Domain 作成(KMS 暗号化)
- [ ] 3 段階 Repository 作成(dev/stg/prod)
- [ ] dev-repo に external connection 設定(npm/pypi)
- [ ] stg-repo・prod-repo に upstream 設定
- [ ] Dependency Origin Controls 有効化
- [ ] IAM roles:developer・security・ci-cd
- [ ] VPC endpoint(該当時)
セキュリティチェックリスト
- [ ] IAM 最小権限設定
- [ ] prod-repo publish 禁止・read-only
- [ ] CloudTrail 監査ログ有効化
- [ ] Dependency Origin Controls(Dependency Confusion対策)
- [ ] KMS 暗号化有効化
- [ ] VPC endpoint プライベートアクセス
運用チェックリスト
- [ ] Package promotion workflow 文書化
- [ ] Retention policy 設定(storage 最適化)
- [ ] Cost monitoring dashboard
- [ ] Package security audit schedule
- [ ] Team training 完了
まとめ
AWS CodeArtifact は 「npm・PyPI・Maven・NuGet 等の多言語パッケージを一元管理し、社内共有・Dependency Confusion 対策・外部レジストリキャッシングを実現するフルマネージドアーティファクトリポジトリサービス」 です。
3 段階 repository 構成(dev → stg → prod)で package の段階的承認フロー・Dependency Origin Controls で supply chain 攻撃を完全防止・Pull-Through Cache で CI/CD ビルド 30% 高速化が実現でき、エンタープライズグレードの安全・効率的なパッケージ管理基盤を AWS ネイティブで構築できます。
最終更新:2026-04-26 バージョン:v2.0