Terraform for uploading to Xet over AWS PrivateLink
Browse files- .gitattributes +1 -35
- README.md +73 -0
- main.tf +77 -0
- outputs.tf +14 -0
- terraform.tfvars.example +11 -0
- variables.tf +31 -0
- verify-privatelink.sh +50 -0
.gitattributes
CHANGED
|
@@ -1,35 +1 @@
|
|
| 1 |
-
*.
|
| 2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 1 |
+
*.sh text eol=lf
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Uploading to Xet Storage over AWS PrivateLink
|
| 2 |
+
|
| 3 |
+
Terraform for pushing data into Hugging Face from your own VPC without it
|
| 4 |
+
leaving the AWS network. Your upload traffic stops being metered as internet
|
| 5 |
+
egress and becomes endpoint data processing instead.
|
| 6 |
+
|
| 7 |
+
Your hostname, your client and your credentials all stay the same. The only
|
| 8 |
+
change is a DNS override inside your VPC.
|
| 9 |
+
|
| 10 |
+
## What we exchange
|
| 11 |
+
|
| 12 |
+
Send us your **AWS account ID** and the **region your upload instances run in**.
|
| 13 |
+
We send back:
|
| 14 |
+
|
| 15 |
+
- `service_name`, of the form `com.amazonaws.vpce.us-east-1.vpce-svc-0123456789abcdef0`
|
| 16 |
+
- the Availability Zones we serve, given as **AZ IDs** (`use1-az1`, ...)
|
| 17 |
+
|
| 18 |
+
## Apply
|
| 19 |
+
|
| 20 |
+
```bash
|
| 21 |
+
cp terraform.tfvars.example terraform.tfvars
|
| 22 |
+
# fill in service_name, vpc_id, subnet_ids, client_cidr_blocks
|
| 23 |
+
terraform init
|
| 24 |
+
terraform apply
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
Pick your subnets by AZ ID, not AZ name. `us-east-1a` is a different physical
|
| 28 |
+
zone in every AWS account, so matching on the name silently puts your endpoint
|
| 29 |
+
in a different zone from your compute. This lists both for your account:
|
| 30 |
+
|
| 31 |
+
```bash
|
| 32 |
+
aws ec2 describe-availability-zones \
|
| 33 |
+
--query 'AvailabilityZones[].[ZoneName,ZoneId]' --output table
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
The apply **blocks on the endpoint** while it sits in `pendingAcceptance`: we
|
| 37 |
+
accept every connection by hand. Send us the `endpoint_id` output while it
|
| 38 |
+
waits, or let it time out and re-run once we confirm.
|
| 39 |
+
|
| 40 |
+
## What it creates
|
| 41 |
+
|
| 42 |
+
| Resource | Why |
|
| 43 |
+
|---|---|
|
| 44 |
+
| `aws_vpc_endpoint.cas` | The interface endpoint into our upload service |
|
| 45 |
+
| `aws_security_group.endpoint` | Accepts 443 from your upload clients only |
|
| 46 |
+
| `aws_route53_zone.xethub` | Private zone for `xethub.hf.co`, scoped to your VPC |
|
| 47 |
+
| `aws_route53_record.cas_server` | Points `cas-server.xethub.hf.co` at your endpoint |
|
| 48 |
+
|
| 49 |
+
The hosted zone is private to the VPC you pass in. It does not affect public
|
| 50 |
+
DNS, and the TLS certificate we serve already covers that hostname, so nothing
|
| 51 |
+
in your client needs to know.
|
| 52 |
+
|
| 53 |
+
For a VPC outside `us-east-1`, set `service_region = "us-east-1"` and Terraform
|
| 54 |
+
attaches a cross-region endpoint instead.
|
| 55 |
+
|
| 56 |
+
## Verify
|
| 57 |
+
|
| 58 |
+
Run `./verify-privatelink.sh` from an instance in that VPC. Each check says in
|
| 59 |
+
its comments what it proves, and the script fails loudly rather than passing on
|
| 60 |
+
a half-working path.
|
| 61 |
+
|
| 62 |
+
## Upload
|
| 63 |
+
|
| 64 |
+
```bash
|
| 65 |
+
hf upload your-org/your-model ./local-dir
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
Use `hf` rather than the S3 API. The client chunks and deduplicates locally, so
|
| 69 |
+
it only sends blocks we do not already hold. In our own test, 80 MB of input
|
| 70 |
+
became 60 MB on the wire because the duplicate blocks were never sent.
|
| 71 |
+
|
| 72 |
+
Authentication and commit calls still go to `huggingface.co` over the internet.
|
| 73 |
+
The volume is negligible next to your data, but egress there has to stay open.
|
main.tf
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Consumer side of the Hugging Face Xet PrivateLink setup.
|
| 2 |
+
#
|
| 3 |
+
# Creates the interface endpoint into our upload service, and the private DNS
|
| 4 |
+
# override that puts cas-server.xethub.hf.co on it inside your VPC. Nothing
|
| 5 |
+
# here is specific to Hugging Face beyond the two hostnames.
|
| 6 |
+
|
| 7 |
+
terraform {
|
| 8 |
+
required_version = ">= 1.5"
|
| 9 |
+
required_providers {
|
| 10 |
+
aws = { source = "hashicorp/aws", version = "~> 6.0" }
|
| 11 |
+
}
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
resource "aws_security_group" "endpoint" {
|
| 15 |
+
name_prefix = "xet-privatelink-"
|
| 16 |
+
description = "Xet upload endpoint"
|
| 17 |
+
vpc_id = var.vpc_id
|
| 18 |
+
|
| 19 |
+
ingress {
|
| 20 |
+
description = "HTTPS from your upload clients"
|
| 21 |
+
from_port = 443
|
| 22 |
+
to_port = 443
|
| 23 |
+
protocol = "tcp"
|
| 24 |
+
cidr_blocks = var.client_cidr_blocks
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
egress {
|
| 28 |
+
from_port = 0
|
| 29 |
+
to_port = 0
|
| 30 |
+
protocol = "-1"
|
| 31 |
+
cidr_blocks = ["0.0.0.0/0"]
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
tags = var.tags
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
# Created in pendingAcceptance: we accept every connection by hand, so this
|
| 38 |
+
# apply blocks until we do. Send us the endpoint ID while it waits, or let it
|
| 39 |
+
# time out and re-run once we confirm.
|
| 40 |
+
resource "aws_vpc_endpoint" "cas" {
|
| 41 |
+
vpc_id = var.vpc_id
|
| 42 |
+
service_name = var.service_name
|
| 43 |
+
service_region = var.service_region
|
| 44 |
+
vpc_endpoint_type = "Interface"
|
| 45 |
+
subnet_ids = var.subnet_ids
|
| 46 |
+
security_group_ids = [aws_security_group.endpoint.id]
|
| 47 |
+
|
| 48 |
+
# We do not advertise a private DNS name, the zone below does the override.
|
| 49 |
+
private_dns_enabled = false
|
| 50 |
+
|
| 51 |
+
timeouts {
|
| 52 |
+
create = "30m"
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
tags = var.tags
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
# Private to this VPC: it does not affect public DNS, and the certificate we
|
| 59 |
+
# serve already covers the hostname.
|
| 60 |
+
resource "aws_route53_zone" "xethub" {
|
| 61 |
+
name = "xethub.hf.co"
|
| 62 |
+
comment = "Xet PrivateLink override, private to this VPC"
|
| 63 |
+
|
| 64 |
+
vpc {
|
| 65 |
+
vpc_id = var.vpc_id
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
tags = var.tags
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
resource "aws_route53_record" "cas_server" {
|
| 72 |
+
zone_id = aws_route53_zone.xethub.zone_id
|
| 73 |
+
name = "cas-server.xethub.hf.co"
|
| 74 |
+
type = "CNAME"
|
| 75 |
+
ttl = 60
|
| 76 |
+
records = [aws_vpc_endpoint.cas.dns_entry[0].dns_name]
|
| 77 |
+
}
|
outputs.tf
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
output "endpoint_id" {
|
| 2 |
+
description = "Send this to us so we can accept the connection."
|
| 3 |
+
value = aws_vpc_endpoint.cas.id
|
| 4 |
+
}
|
| 5 |
+
|
| 6 |
+
output "endpoint_state" {
|
| 7 |
+
description = "pendingAcceptance until we accept, then available."
|
| 8 |
+
value = aws_vpc_endpoint.cas.state
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
output "endpoint_dns_name" {
|
| 12 |
+
description = "What cas-server.xethub.hf.co now points to inside this VPC."
|
| 13 |
+
value = aws_vpc_endpoint.cas.dns_entry[0].dns_name
|
| 14 |
+
}
|
terraform.tfvars.example
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
service_name = "com.amazonaws.vpce.us-east-1.vpce-svc-REPLACE_ME"
|
| 2 |
+
vpc_id = "vpc-xxxxxxxx"
|
| 3 |
+
subnet_ids = ["subnet-aaaaaaaa", "subnet-bbbbbbbb"]
|
| 4 |
+
client_cidr_blocks = ["10.0.0.0/16"]
|
| 5 |
+
|
| 6 |
+
# Uncomment when your VPC is not in us-east-1.
|
| 7 |
+
# service_region = "us-east-1"
|
| 8 |
+
|
| 9 |
+
tags = {
|
| 10 |
+
Project = "xet-upload"
|
| 11 |
+
}
|
variables.tf
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
variable "service_name" {
|
| 2 |
+
description = "Endpoint service name we sent you, of the form com.amazonaws.vpce.us-east-1.vpce-svc-0123456789abcdef0."
|
| 3 |
+
type = string
|
| 4 |
+
}
|
| 5 |
+
|
| 6 |
+
variable "service_region" {
|
| 7 |
+
description = "Region hosting the service. Leave null when your VPC is in the same region; set it to attach a cross-region endpoint."
|
| 8 |
+
type = string
|
| 9 |
+
default = null
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
variable "vpc_id" {
|
| 13 |
+
description = "VPC your upload clients run in."
|
| 14 |
+
type = string
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
variable "subnet_ids" {
|
| 18 |
+
description = "One subnet per zone you upload from. Pick them by AZ ID rather than AZ name, and only zones we serve: us-east-1a is a different physical zone in every AWS account."
|
| 19 |
+
type = list(string)
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
variable "client_cidr_blocks" {
|
| 23 |
+
description = "CIDRs allowed to reach the endpoint on 443. Narrow this to the subnets your upload clients run in."
|
| 24 |
+
type = list(string)
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
variable "tags" {
|
| 28 |
+
description = "Tags applied to every resource here."
|
| 29 |
+
type = map(string)
|
| 30 |
+
default = {}
|
| 31 |
+
}
|
verify-privatelink.sh
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# Verify that Xet uploads leave this VPC over the PrivateLink endpoint.
|
| 3 |
+
# Run from an instance inside the VPC that holds the interface endpoint.
|
| 4 |
+
set -uo pipefail
|
| 5 |
+
|
| 6 |
+
HOST=cas-server.xethub.hf.co
|
| 7 |
+
PROBE="https://${HOST}/v1/xorbs/aaaa/bbbb"
|
| 8 |
+
|
| 9 |
+
echo "1. Does the hostname resolve to your endpoint?"
|
| 10 |
+
# Expect the private addresses of your endpoint network interfaces, not a
|
| 11 |
+
# public IP. A public IP means the private hosted zone is not being consulted.
|
| 12 |
+
getent hosts "$HOST" | sed 's/^/ /' || { echo " FAIL: does not resolve"; exit 1; }
|
| 13 |
+
|
| 14 |
+
echo
|
| 15 |
+
echo "2. Does the endpoint answer, and is our certificate valid?"
|
| 16 |
+
# 401 is the success case here: it proves TLS terminated correctly and our
|
| 17 |
+
# authentication layer replied. Anything other than 000 means the path works.
|
| 18 |
+
for i in $(seq 1 18); do
|
| 19 |
+
code=$(curl -sS -o /dev/null -m 10 -w '%{http_code}' "$PROBE" 2>/dev/null)
|
| 20 |
+
if [ -n "$code" ] && [ "$code" != "000" ]; then
|
| 21 |
+
echo " HTTP $code (401 expected, and means success)"
|
| 22 |
+
break
|
| 23 |
+
fi
|
| 24 |
+
echo " attempt $i: no answer yet, the data plane may still be converging"
|
| 25 |
+
sleep 10
|
| 26 |
+
done
|
| 27 |
+
[ "${code:-000}" = "000" ] && { echo " FAIL: no answer after 3 minutes"; exit 1; }
|
| 28 |
+
|
| 29 |
+
echo
|
| 30 |
+
echo "3. Which certificate is presented?"
|
| 31 |
+
# Expect CN=*.xethub.hf.co issued by Amazon. A different name means SNI is not
|
| 32 |
+
# reaching us intact.
|
| 33 |
+
openssl s_client -connect "${HOST}:443" -servername "$HOST" </dev/null 2>/dev/null \
|
| 34 |
+
| openssl x509 -noout -subject -issuer | sed 's/^/ /'
|
| 35 |
+
|
| 36 |
+
echo
|
| 37 |
+
echo "4. Which CAS endpoint does the Hub hand out?"
|
| 38 |
+
# Must be https://cas-server.xethub.hf.co, the hostname your private zone
|
| 39 |
+
# overrides. If it differs, the DNS override does not apply to your traffic.
|
| 40 |
+
if [ -n "${HF_TOKEN:-}" ]; then
|
| 41 |
+
curl -sS -H "Authorization: Bearer ${HF_TOKEN}" \
|
| 42 |
+
"https://huggingface.co/api/models/${HF_TEST_REPO:-models/none}/xet-write-token/main" 2>/dev/null \
|
| 43 |
+
| python3 -c 'import sys,json; print(" casUrl:", json.load(sys.stdin).get("casUrl"))' 2>/dev/null \
|
| 44 |
+
|| echo " skipped: set HF_TEST_REPO to a dataset you can write to"
|
| 45 |
+
else
|
| 46 |
+
echo " skipped: HF_TOKEN not set"
|
| 47 |
+
fi
|
| 48 |
+
|
| 49 |
+
echo
|
| 50 |
+
echo "All checks passed. Uploads from this VPC will use the private path."
|