-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[client][management] feat: TPM/Secure Enclave certificate-based device authentication #5881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
10cf63e
feat(proto): add device certificate authentication RPCs
967227d
feat(store): add DeviceCertificate/DeviceEnrollment models and store …
22be237
feat(secretenc): add AES-256-GCM envelope encryption for CA private keys
28c65b4
feat(devicepki): in-process CA, external CA adapters, and attestation…
076cf3f
feat(management/grpc): mTLS enforcement, device enrollment RPC, TPM/S…
f803028
feat(management/http): device auth HTTP API — CA config, enrollments,…
d3a3a6c
feat(client/tpm): TPM 2.0 hardware attestation provider
81dadec
feat(client): enrollment manager and mTLS connection upgrade
473e59d
feat(ci): GitHub Actions workflows for device auth and TPM integratio…
da0ab24
chore: dev stand, demo tools, and infrastructure updates
c139c29
docs: add DEVICE-SECURITY.md — architecture, sequence diagrams, known…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| name: Device Auth Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: [feature/tpm-cert-auth] | ||
| pull_request: | ||
| branches: [main] | ||
| paths: | ||
| - 'management/server/deviceauth/**' | ||
| - 'management/server/devicepki/**' | ||
| - 'management/server/http/handlers/device_auth/**' | ||
| - 'management/internals/shared/grpc/**' | ||
| - 'client/internal/enrollment/**' | ||
| - 'client/internal/tpm/**' | ||
| - 'shared/management/**' | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| device-auth-tests: | ||
| name: Device Auth Tests (no sudo required) | ||
| runs-on: ubuntu-22.04 | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version-file: "go.mod" | ||
| cache: true | ||
|
|
||
| - name: Run device auth unit tests | ||
| run: | | ||
| go test -count=1 -timeout 300s -race \ | ||
| ./management/server/deviceauth/... \ | ||
| ./management/server/devicepki/... \ | ||
| ./management/server/http/handlers/device_auth/... \ | ||
| ./management/internals/shared/grpc/... \ | ||
| ./client/internal/enrollment/... \ | ||
| ./client/internal/tpm/... \ | ||
| ./shared/management/... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| name: E2E Device Auth Tests | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [main] | ||
| types: [opened, synchronize, reopened] | ||
| paths: | ||
| - 'management/**' | ||
| - 'client/**' | ||
| - 'netbird-stand/**' | ||
| - 'scripts/e2e-*.sh' | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref || github.actor_id }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| e2e-device-auth: | ||
| name: E2E Device Auth (docker-compose stand) | ||
| runs-on: ubuntu-22.04 | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version-file: go.mod | ||
| cache: true | ||
|
|
||
| - name: Build management server | ||
| run: go build -o bin/management ./management/cmd/management | ||
|
|
||
| # TODO: Start management server - requires testdata/mgmt-e2e.json | ||
| # Uncomment when mgmt-e2e.json config is available: | ||
| # - name: Start management server | ||
| # run: | | ||
| # ./bin/management --config testdata/mgmt-e2e.json --port 8080 & | ||
| # echo "Management server started (PID $!)" | ||
| # env: | ||
| # NETBIRD_STORE_ENGINE: sqlite | ||
|
|
||
| - name: Validate E2E scripts | ||
| run: | | ||
| chmod +x scripts/e2e-lib.sh scripts/e2e-device-auth.sh | ||
| bash -n scripts/e2e-lib.sh | ||
| bash -n scripts/e2e-device-auth.sh | ||
| echo "Script syntax OK" | ||
| # Note: Full E2E requires management server with testdata/mgmt-e2e.json | ||
| # Run manually: NETBIRD_API_URL=http://localhost:8080 bash scripts/e2e-device-auth.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| name: TPM Integration Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| - feature/tpm-cert-auth | ||
| paths: | ||
| - 'client/internal/tpm/**' | ||
| - 'client/internal/enrollment/**' | ||
| - 'management/server/devicepki/**' | ||
| - 'management/server/deviceinventory/**' | ||
| pull_request: | ||
| paths: | ||
| - 'client/internal/tpm/**' | ||
| - 'client/internal/enrollment/**' | ||
| - 'management/server/devicepki/**' | ||
| - 'management/server/deviceinventory/**' | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref || github.actor_id }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| tpm-integration: | ||
| name: "TPM 2.0 Integration (swtpm)" | ||
| runs-on: ubuntu-22.04 | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Install Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version-file: "go.mod" | ||
|
|
||
| - name: Install swtpm and tpm2-tools | ||
| run: | | ||
| sudo apt-get update -q | ||
| sudo apt-get install -y --no-install-recommends \ | ||
| swtpm \ | ||
| tpm2-tools \ | ||
| libtpms-dev \ | ||
| netcat-openbsd | ||
|
|
||
| - name: Start swtpm (TCP socket mode) | ||
| run: | | ||
| mkdir -p /tmp/swtpm-state | ||
| swtpm socket \ | ||
| --tpmstate dir=/tmp/swtpm-state \ | ||
| --tpm2 \ | ||
| --flags not-need-init \ | ||
| --server type=tcp,port=2321 \ | ||
| --ctrl type=tcp,port=2322 \ | ||
| --daemon | ||
| # Wait for swtpm to be ready on the command port. | ||
| for i in $(seq 1 15); do | ||
| nc -z localhost 2321 2>/dev/null && break | ||
| sleep 1 | ||
| done | ||
| echo "NETBIRD_TPM_SIMULATOR=localhost:2321" >> $GITHUB_ENV | ||
| echo "swtpm ready on localhost:2321" | ||
|
|
||
| - name: Cache Go modules | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| ~/.cache/go-build | ||
| ~/go/pkg/mod | ||
| key: ${{ runner.os }}-go-tpm-${{ hashFiles('**/go.sum') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-go-tpm- | ||
|
|
||
| - name: Run TPM unit tests (mock provider) | ||
| env: | ||
| NETBIRD_TPM_SIMULATOR: ${{ env.NETBIRD_TPM_SIMULATOR }} | ||
| run: go test ./client/internal/tpm/... -v -count=1 -timeout 60s | ||
|
|
||
| - name: Run TPM integration tests (swtpm TCP or /dev/tpmrm0) | ||
| env: | ||
| NETBIRD_TPM_SIMULATOR: ${{ env.NETBIRD_TPM_SIMULATOR }} | ||
| run: | | ||
| go test ./client/internal/tpm/... \ | ||
| -v \ | ||
| -count=1 \ | ||
| -timeout 120s \ | ||
| -tags integration | ||
|
|
||
| - name: Run enrollment manager tests | ||
| run: go test ./client/internal/enrollment/... -v -count=1 -timeout 60s | ||
|
|
||
| - name: Run devicepki tests | ||
| run: go test ./management/server/devicepki/... -v -count=1 -timeout 60s | ||
|
|
||
| - name: Run deviceinventory tests | ||
| run: go test ./management/server/deviceinventory/... -v -count=1 -timeout 60s | ||
|
|
||
| attestation-verification: | ||
| name: "Attestation Verification Unit Tests" | ||
| runs-on: ubuntu-22.04 | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Install Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version-file: "go.mod" | ||
|
|
||
| - name: Cache Go modules | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| ~/.cache/go-build | ||
| ~/go/pkg/mod | ||
| key: ${{ runner.os }}-go-attestation-${{ hashFiles('**/go.sum') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-go-attestation- | ||
|
|
||
| - name: Run attestation verification tests | ||
| run: | | ||
| go test ./management/server/devicepki/... \ | ||
| -v \ | ||
| -count=1 \ | ||
| -run TestVerifyAttestation \ | ||
| -timeout 30s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't enroll device certificates on plain-HTTP management connections.
This block runs
EnsureCertificatewhenever the platform provider is available, but the resulting certificate is only usable whenmgmTlsEnabledis true. Onhttp://management URLs that means we still perform attestation/enrollment and create server-side enrollment state even though the client can never upgrade the channel to mTLS. Gate the whole enrollment path behindmgmTlsEnabled.Suggested change
📝 Committable suggestion
🤖 Prompt for AI Agents