mirror of
https://github.com/fosrl/newt.git
synced 2026-03-26 20:46:41 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08952c20c5 | ||
|
|
5e60da37d1 | ||
|
|
53d79aea5a | ||
|
|
0f6852b681 | ||
|
|
2b8e280f2e | ||
|
|
3a377d43de | ||
|
|
792057cf6c | ||
|
|
57afe91e85 | ||
|
|
3389088c43 | ||
|
|
e73150c187 | ||
|
|
18556f34b2 | ||
|
|
66c235624a |
466
.github/workflows/cicd.yml
vendored
466
.github/workflows/cicd.yml
vendored
@@ -20,16 +20,6 @@ on:
|
|||||||
description: "SemVer version to release (e.g., 1.2.3, no leading 'v')"
|
description: "SemVer version to release (e.g., 1.2.3, no leading 'v')"
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
publish_latest:
|
|
||||||
description: "Also publish the 'latest' image tag"
|
|
||||||
required: true
|
|
||||||
type: boolean
|
|
||||||
default: false
|
|
||||||
publish_minor:
|
|
||||||
description: "Also publish the 'major.minor' image tag (e.g., 1.2)"
|
|
||||||
required: true
|
|
||||||
type: boolean
|
|
||||||
default: false
|
|
||||||
target_branch:
|
target_branch:
|
||||||
description: "Branch to tag"
|
description: "Branch to tag"
|
||||||
required: false
|
required: false
|
||||||
@@ -86,9 +76,6 @@ jobs:
|
|||||||
name: Build and Release
|
name: Build and Release
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
timeout-minutes: 120
|
timeout-minutes: 120
|
||||||
env:
|
|
||||||
DOCKERHUB_IMAGE: docker.io/fosrl/${{ github.event.repository.name }}
|
|
||||||
GHCR_IMAGE: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
@@ -96,37 +83,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Capture created timestamp
|
|
||||||
run: echo "IMAGE_CREATED=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_ENV
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Set up QEMU
|
|
||||||
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
|
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
|
||||||
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
|
|
||||||
with:
|
|
||||||
registry: docker.io
|
|
||||||
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
|
|
||||||
|
|
||||||
- name: Log in to GHCR
|
|
||||||
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
|
|
||||||
with:
|
|
||||||
registry: ghcr.io
|
|
||||||
username: ${{ github.actor }}
|
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Normalize image names to lowercase
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
echo "GHCR_IMAGE=${GHCR_IMAGE,,}" >> "$GITHUB_ENV"
|
|
||||||
echo "DOCKERHUB_IMAGE=${DOCKERHUB_IMAGE,,}" >> "$GITHUB_ENV"
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Extract tag name
|
- name: Extract tag name
|
||||||
env:
|
env:
|
||||||
EVENT_NAME: ${{ github.event_name }}
|
EVENT_NAME: ${{ github.event_name }}
|
||||||
@@ -166,16 +122,6 @@ jobs:
|
|||||||
echo "Tag ${TAG} not visible after waiting"; exit 1
|
echo "Tag ${TAG} not visible after waiting"; exit 1
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- name: Update version in main.go
|
|
||||||
run: |
|
|
||||||
TAG=${{ env.TAG }}
|
|
||||||
if [ -f main.go ]; then
|
|
||||||
sed -i 's/version_replaceme/'"$TAG"'/' main.go
|
|
||||||
echo "Updated main.go with version $TAG"
|
|
||||||
else
|
|
||||||
echo "main.go not found"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Ensure repository is at the tagged commit (dispatch only)
|
- name: Ensure repository is at the tagged commit (dispatch only)
|
||||||
if: ${{ github.event_name == 'workflow_dispatch' }}
|
if: ${{ github.event_name == 'workflow_dispatch' }}
|
||||||
run: |
|
run: |
|
||||||
@@ -200,38 +146,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
go-version-file: go.mod
|
go-version-file: go.mod
|
||||||
|
|
||||||
- name: Resolve publish-latest flag
|
|
||||||
env:
|
|
||||||
EVENT_NAME: ${{ github.event_name }}
|
|
||||||
PL_INPUT: ${{ inputs.publish_latest }}
|
|
||||||
PL_VAR: ${{ vars.PUBLISH_LATEST }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
val="false"
|
|
||||||
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
|
|
||||||
if [ "${PL_INPUT}" = "true" ]; then val="true"; fi
|
|
||||||
else
|
|
||||||
if [ "${PL_VAR}" = "true" ]; then val="true"; fi
|
|
||||||
fi
|
|
||||||
echo "PUBLISH_LATEST=$val" >> $GITHUB_ENV
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Resolve publish-minor flag
|
|
||||||
env:
|
|
||||||
EVENT_NAME: ${{ github.event_name }}
|
|
||||||
PM_INPUT: ${{ inputs.publish_minor }}
|
|
||||||
PM_VAR: ${{ vars.PUBLISH_MINOR }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
val="false"
|
|
||||||
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
|
|
||||||
if [ "${PM_INPUT}" = "true" ]; then val="true"; fi
|
|
||||||
else
|
|
||||||
if [ "${PM_VAR}" = "true" ]; then val="true"; fi
|
|
||||||
fi
|
|
||||||
echo "PUBLISH_MINOR=$val" >> $GITHUB_ENV
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Cache Go modules
|
- name: Cache Go modules
|
||||||
if: ${{ hashFiles('**/go.sum') != '' }}
|
if: ${{ hashFiles('**/go.sum') != '' }}
|
||||||
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
|
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
|
||||||
@@ -250,326 +164,6 @@ jobs:
|
|||||||
go test ./... -race -covermode=atomic
|
go test ./... -race -covermode=atomic
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- name: Resolve license fallback
|
|
||||||
run: echo "IMAGE_LICENSE=${{ github.event.repository.license.spdx_id || 'NOASSERTION' }}" >> $GITHUB_ENV
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Resolve registries list (GHCR always, Docker Hub only if creds)
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
images="${GHCR_IMAGE}"
|
|
||||||
if [ -n "${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}" ] && [ -n "${{ secrets.DOCKER_HUB_USERNAME }}" ]; then
|
|
||||||
images="${images}\n${DOCKERHUB_IMAGE}"
|
|
||||||
fi
|
|
||||||
{
|
|
||||||
echo 'IMAGE_LIST<<EOF'
|
|
||||||
echo -e "$images"
|
|
||||||
echo 'EOF'
|
|
||||||
} >> "$GITHUB_ENV"
|
|
||||||
- name: Docker meta
|
|
||||||
id: meta
|
|
||||||
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
|
|
||||||
with:
|
|
||||||
images: ${{ env.IMAGE_LIST }}
|
|
||||||
tags: |
|
|
||||||
type=semver,pattern={{version}},value=${{ env.TAG }}
|
|
||||||
type=semver,pattern={{major}}.{{minor}},value=${{ env.TAG }},enable=${{ env.PUBLISH_MINOR == 'true' && env.IS_RC != 'true' }}
|
|
||||||
type=raw,value=latest,enable=${{ env.IS_RC != 'true' }}
|
|
||||||
flavor: |
|
|
||||||
latest=false
|
|
||||||
labels: |
|
|
||||||
org.opencontainers.image.title=${{ github.event.repository.name }}
|
|
||||||
org.opencontainers.image.version=${{ env.TAG }}
|
|
||||||
org.opencontainers.image.revision=${{ github.sha }}
|
|
||||||
org.opencontainers.image.source=${{ github.event.repository.html_url }}
|
|
||||||
org.opencontainers.image.url=${{ github.event.repository.html_url }}
|
|
||||||
org.opencontainers.image.documentation=${{ github.event.repository.html_url }}
|
|
||||||
org.opencontainers.image.description=${{ github.event.repository.description }}
|
|
||||||
org.opencontainers.image.licenses=${{ env.IMAGE_LICENSE }}
|
|
||||||
org.opencontainers.image.created=${{ env.IMAGE_CREATED }}
|
|
||||||
org.opencontainers.image.ref.name=${{ env.TAG }}
|
|
||||||
org.opencontainers.image.authors=${{ github.repository_owner }}
|
|
||||||
- name: Echo build config (non-secret)
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
IMAGE_TITLE: ${{ github.event.repository.name }}
|
|
||||||
IMAGE_VERSION: ${{ env.TAG }}
|
|
||||||
IMAGE_REVISION: ${{ github.sha }}
|
|
||||||
IMAGE_SOURCE_URL: ${{ github.event.repository.html_url }}
|
|
||||||
IMAGE_URL: ${{ github.event.repository.html_url }}
|
|
||||||
IMAGE_DESCRIPTION: ${{ github.event.repository.description }}
|
|
||||||
IMAGE_LICENSE: ${{ env.IMAGE_LICENSE }}
|
|
||||||
DOCKERHUB_IMAGE: ${{ env.DOCKERHUB_IMAGE }}
|
|
||||||
GHCR_IMAGE: ${{ env.GHCR_IMAGE }}
|
|
||||||
DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USERNAME }}
|
|
||||||
REPO: ${{ github.repository }}
|
|
||||||
OWNER: ${{ github.repository_owner }}
|
|
||||||
WORKFLOW_REF: ${{ github.workflow_ref }}
|
|
||||||
REF: ${{ github.ref }}
|
|
||||||
REF_NAME: ${{ github.ref_name }}
|
|
||||||
RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
echo "=== OCI Label Values ==="
|
|
||||||
echo "org.opencontainers.image.title=${IMAGE_TITLE}"
|
|
||||||
echo "org.opencontainers.image.version=${IMAGE_VERSION}"
|
|
||||||
echo "org.opencontainers.image.revision=${IMAGE_REVISION}"
|
|
||||||
echo "org.opencontainers.image.source=${IMAGE_SOURCE_URL}"
|
|
||||||
echo "org.opencontainers.image.url=${IMAGE_URL}"
|
|
||||||
echo "org.opencontainers.image.description=${IMAGE_DESCRIPTION}"
|
|
||||||
echo "org.opencontainers.image.licenses=${IMAGE_LICENSE}"
|
|
||||||
echo
|
|
||||||
echo "=== Images ==="
|
|
||||||
echo "DOCKERHUB_IMAGE=${DOCKERHUB_IMAGE}"
|
|
||||||
echo "GHCR_IMAGE=${GHCR_IMAGE}"
|
|
||||||
echo "DOCKER_HUB_USERNAME=${DOCKER_HUB_USER}"
|
|
||||||
echo
|
|
||||||
echo "=== GitHub Kontext ==="
|
|
||||||
echo "repository=${REPO}"
|
|
||||||
echo "owner=${OWNER}"
|
|
||||||
echo "workflow_ref=${WORKFLOW_REF}"
|
|
||||||
echo "ref=${REF}"
|
|
||||||
echo "ref_name=${REF_NAME}"
|
|
||||||
echo "run_url=${RUN_URL}"
|
|
||||||
echo
|
|
||||||
echo "=== docker/metadata-action outputs (Tags/Labels), raw ==="
|
|
||||||
echo "::group::tags"
|
|
||||||
echo "${{ steps.meta.outputs.tags }}"
|
|
||||||
echo "::endgroup::"
|
|
||||||
echo "::group::labels"
|
|
||||||
echo "${{ steps.meta.outputs.labels }}"
|
|
||||||
echo "::endgroup::"
|
|
||||||
- name: Build and push (Docker Hub + GHCR)
|
|
||||||
id: build
|
|
||||||
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
push: true
|
|
||||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
cache-from: type=gha,scope=${{ github.repository }}
|
|
||||||
cache-to: type=gha,mode=max,scope=${{ github.repository }}
|
|
||||||
provenance: mode=max
|
|
||||||
sbom: true
|
|
||||||
|
|
||||||
- name: Compute image digest refs
|
|
||||||
run: |
|
|
||||||
echo "DIGEST=${{ steps.build.outputs.digest }}" >> $GITHUB_ENV
|
|
||||||
echo "GHCR_REF=$GHCR_IMAGE@${{ steps.build.outputs.digest }}" >> $GITHUB_ENV
|
|
||||||
echo "DH_REF=$DOCKERHUB_IMAGE@${{ steps.build.outputs.digest }}" >> $GITHUB_ENV
|
|
||||||
echo "Built digest: ${{ steps.build.outputs.digest }}"
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Attest build provenance (GHCR)
|
|
||||||
id: attest-ghcr
|
|
||||||
uses: actions/attest-build-provenance@00014ed6ed5efc5b1ab7f7f34a39eb55d41aa4f8 # v3.1.0
|
|
||||||
with:
|
|
||||||
subject-name: ${{ env.GHCR_IMAGE }}
|
|
||||||
subject-digest: ${{ steps.build.outputs.digest }}
|
|
||||||
push-to-registry: true
|
|
||||||
show-summary: true
|
|
||||||
|
|
||||||
- name: Attest build provenance (Docker Hub)
|
|
||||||
continue-on-error: true
|
|
||||||
id: attest-dh
|
|
||||||
uses: actions/attest-build-provenance@00014ed6ed5efc5b1ab7f7f34a39eb55d41aa4f8 # v3.1.0
|
|
||||||
with:
|
|
||||||
subject-name: index.docker.io/fosrl/${{ github.event.repository.name }}
|
|
||||||
subject-digest: ${{ steps.build.outputs.digest }}
|
|
||||||
push-to-registry: true
|
|
||||||
show-summary: true
|
|
||||||
|
|
||||||
- name: Install cosign
|
|
||||||
uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0
|
|
||||||
with:
|
|
||||||
cosign-release: 'v3.0.2'
|
|
||||||
|
|
||||||
- name: Sanity check cosign private key
|
|
||||||
env:
|
|
||||||
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }}
|
|
||||||
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
cosign public-key --key env://COSIGN_PRIVATE_KEY >/dev/null
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Sign GHCR image (digest) with key (recursive)
|
|
||||||
env:
|
|
||||||
COSIGN_YES: "true"
|
|
||||||
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }}
|
|
||||||
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
echo "Signing ${GHCR_REF} (digest) recursively with provided key"
|
|
||||||
cosign sign --key env://COSIGN_PRIVATE_KEY --recursive "${GHCR_REF}"
|
|
||||||
echo "Waiting 30 seconds for signatures to propagate..."
|
|
||||||
sleep 30
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Generate SBOM (SPDX JSON)
|
|
||||||
uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # v0.33.1
|
|
||||||
with:
|
|
||||||
image-ref: ${{ env.GHCR_IMAGE }}@${{ steps.build.outputs.digest }}
|
|
||||||
format: spdx-json
|
|
||||||
output: sbom.spdx.json
|
|
||||||
|
|
||||||
- name: Validate SBOM JSON
|
|
||||||
run: jq -e . sbom.spdx.json >/dev/null
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Minify SBOM JSON (optional hardening)
|
|
||||||
run: jq -c . sbom.spdx.json > sbom.min.json && mv sbom.min.json sbom.spdx.json
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Create SBOM attestation (GHCR, private key)
|
|
||||||
env:
|
|
||||||
COSIGN_YES: "true"
|
|
||||||
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }}
|
|
||||||
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
cosign attest \
|
|
||||||
--key env://COSIGN_PRIVATE_KEY \
|
|
||||||
--type spdxjson \
|
|
||||||
--predicate sbom.spdx.json \
|
|
||||||
"${GHCR_REF}"
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Create SBOM attestation (Docker Hub, private key)
|
|
||||||
continue-on-error: true
|
|
||||||
env:
|
|
||||||
COSIGN_YES: "true"
|
|
||||||
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }}
|
|
||||||
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
|
|
||||||
COSIGN_DOCKER_MEDIA_TYPES: "1"
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
cosign attest \
|
|
||||||
--key env://COSIGN_PRIVATE_KEY \
|
|
||||||
--type spdxjson \
|
|
||||||
--predicate sbom.spdx.json \
|
|
||||||
"${DH_REF}"
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Keyless sign & verify GHCR digest (OIDC)
|
|
||||||
env:
|
|
||||||
COSIGN_YES: "true"
|
|
||||||
WORKFLOW_REF: ${{ github.workflow_ref }} # owner/repo/.github/workflows/<file>@refs/tags/<tag>
|
|
||||||
ISSUER: https://token.actions.githubusercontent.com
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
echo "Keyless signing ${GHCR_REF}"
|
|
||||||
cosign sign --rekor-url https://rekor.sigstore.dev --recursive "${GHCR_REF}"
|
|
||||||
echo "Verify keyless (OIDC) signature policy on ${GHCR_REF}"
|
|
||||||
cosign verify \
|
|
||||||
--certificate-oidc-issuer "${ISSUER}" \
|
|
||||||
--certificate-identity "https://github.com/${WORKFLOW_REF}" \
|
|
||||||
"${GHCR_REF}" -o text
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Sign Docker Hub image (digest) with key (recursive)
|
|
||||||
continue-on-error: true
|
|
||||||
env:
|
|
||||||
COSIGN_YES: "true"
|
|
||||||
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }}
|
|
||||||
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
|
|
||||||
COSIGN_DOCKER_MEDIA_TYPES: "1"
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
echo "Signing ${DH_REF} (digest) recursively with provided key (Docker media types fallback)"
|
|
||||||
cosign sign --key env://COSIGN_PRIVATE_KEY --recursive "${DH_REF}"
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Keyless sign & verify Docker Hub digest (OIDC)
|
|
||||||
continue-on-error: true
|
|
||||||
env:
|
|
||||||
COSIGN_YES: "true"
|
|
||||||
ISSUER: https://token.actions.githubusercontent.com
|
|
||||||
COSIGN_DOCKER_MEDIA_TYPES: "1"
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
echo "Keyless signing ${DH_REF} (force public-good Rekor)"
|
|
||||||
cosign sign --rekor-url https://rekor.sigstore.dev --recursive "${DH_REF}"
|
|
||||||
echo "Keyless verify via Rekor (strict identity)"
|
|
||||||
if ! cosign verify \
|
|
||||||
--rekor-url https://rekor.sigstore.dev \
|
|
||||||
--certificate-oidc-issuer "${ISSUER}" \
|
|
||||||
--certificate-identity "https://github.com/${{ github.workflow_ref }}" \
|
|
||||||
"${DH_REF}" -o text; then
|
|
||||||
echo "Rekor verify failed — retry offline bundle verify (no Rekor)"
|
|
||||||
if ! cosign verify \
|
|
||||||
--offline \
|
|
||||||
--certificate-oidc-issuer "${ISSUER}" \
|
|
||||||
--certificate-identity "https://github.com/${{ github.workflow_ref }}" \
|
|
||||||
"${DH_REF}" -o text; then
|
|
||||||
echo "Offline bundle verify failed — ignore tlog (TEMP for debugging)"
|
|
||||||
cosign verify \
|
|
||||||
--insecure-ignore-tlog=true \
|
|
||||||
--certificate-oidc-issuer "${ISSUER}" \
|
|
||||||
--certificate-identity "https://github.com/${{ github.workflow_ref }}" \
|
|
||||||
"${DH_REF}" -o text || true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
- name: Verify signature (public key) GHCR digest + tag
|
|
||||||
env:
|
|
||||||
COSIGN_PUBLIC_KEY: ${{ secrets.COSIGN_PUBLIC_KEY }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
TAG_VAR="${TAG}"
|
|
||||||
echo "Verifying (digest) ${GHCR_REF}"
|
|
||||||
cosign verify --key env://COSIGN_PUBLIC_KEY "$GHCR_REF" -o text
|
|
||||||
echo "Verifying (tag) $GHCR_IMAGE:$TAG_VAR"
|
|
||||||
cosign verify --key env://COSIGN_PUBLIC_KEY "$GHCR_IMAGE:$TAG_VAR" -o text
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Verify SBOM attestation (GHCR)
|
|
||||||
env:
|
|
||||||
COSIGN_PUBLIC_KEY: ${{ secrets.COSIGN_PUBLIC_KEY }}
|
|
||||||
run: cosign verify-attestation --key env://COSIGN_PUBLIC_KEY --type spdxjson "$GHCR_REF" -o text
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Verify SLSA provenance (GHCR)
|
|
||||||
env:
|
|
||||||
ISSUER: https://token.actions.githubusercontent.com
|
|
||||||
WFREF: ${{ github.workflow_ref }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
# (optional) show which predicate types are present to aid debugging
|
|
||||||
cosign download attestation "$GHCR_REF" \
|
|
||||||
| jq -r '.payload | @base64d | fromjson | .predicateType' | sort -u || true
|
|
||||||
# Verify the SLSA v1 provenance attestation (predicate URL)
|
|
||||||
cosign verify-attestation \
|
|
||||||
--type 'https://slsa.dev/provenance/v1' \
|
|
||||||
--certificate-oidc-issuer "$ISSUER" \
|
|
||||||
--certificate-identity "https://github.com/${WFREF}" \
|
|
||||||
--rekor-url https://rekor.sigstore.dev \
|
|
||||||
"$GHCR_REF" -o text
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Verify signature (public key) Docker Hub digest
|
|
||||||
continue-on-error: true
|
|
||||||
env:
|
|
||||||
COSIGN_PUBLIC_KEY: ${{ secrets.COSIGN_PUBLIC_KEY }}
|
|
||||||
COSIGN_DOCKER_MEDIA_TYPES: "1"
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
echo "Verifying (digest) ${DH_REF} with Docker media types"
|
|
||||||
cosign verify --key env://COSIGN_PUBLIC_KEY "${DH_REF}" -o text
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Verify signature (public key) Docker Hub tag
|
|
||||||
continue-on-error: true
|
|
||||||
env:
|
|
||||||
COSIGN_PUBLIC_KEY: ${{ secrets.COSIGN_PUBLIC_KEY }}
|
|
||||||
COSIGN_DOCKER_MEDIA_TYPES: "1"
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
echo "Verifying (tag) $DOCKERHUB_IMAGE:$TAG with Docker media types"
|
|
||||||
cosign verify --key env://COSIGN_PUBLIC_KEY "$DOCKERHUB_IMAGE:$TAG" -o text
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
# - name: Trivy scan (GHCR image)
|
# - name: Trivy scan (GHCR image)
|
||||||
# id: trivy
|
# id: trivy
|
||||||
# uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # v0.33.1
|
# uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # v0.33.1
|
||||||
@@ -589,28 +183,46 @@ jobs:
|
|||||||
# sarif_file: trivy-ghcr.sarif
|
# sarif_file: trivy-ghcr.sarif
|
||||||
# category: Image Vulnerability Scan
|
# category: Image Vulnerability Scan
|
||||||
|
|
||||||
- name: Build binaries
|
#- name: Build binaries
|
||||||
env:
|
# env:
|
||||||
CGO_ENABLED: "0"
|
# CGO_ENABLED: "0"
|
||||||
GOFLAGS: "-trimpath"
|
# GOFLAGS: "-trimpath"
|
||||||
|
# run: |
|
||||||
|
# set -euo pipefail
|
||||||
|
# TAG_VAR="${TAG}"
|
||||||
|
# make -j 10 go-build-release tag=$TAG_VAR
|
||||||
|
# shell: bash
|
||||||
|
|
||||||
|
- name: Ensure clean git state for GoReleaser
|
||||||
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
TAG_VAR="${TAG}"
|
echo "Checking git status before GoReleaser..."
|
||||||
make -j 10 go-build-release tag=$TAG_VAR
|
git status --porcelain || true
|
||||||
shell: bash
|
if [ -n "$(git status --porcelain)" ]; then
|
||||||
|
echo "Repository contains local changes. Listing files and diff:"
|
||||||
|
git status --porcelain
|
||||||
|
git --no-pager diff --name-status || true
|
||||||
|
echo "Resetting tracked files to HEAD to ensure a clean release state"
|
||||||
|
git restore --source=HEAD --worktree --staged -- .
|
||||||
|
echo "After reset git status:"
|
||||||
|
git status --porcelain || true
|
||||||
|
else
|
||||||
|
echo "Repository clean."
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Create GitHub Release
|
- name: Run GoReleaser config check
|
||||||
uses: softprops/action-gh-release@5be0e66d93ac7ed76da52eca8bb058f665c3a5fe # v2.4.2
|
uses: goreleaser/goreleaser-action@v6
|
||||||
with:
|
with:
|
||||||
tag_name: ${{ env.TAG }}
|
version: 2.14.0
|
||||||
generate_release_notes: true
|
args: check
|
||||||
prerelease: ${{ env.IS_RC == 'true' }}
|
env:
|
||||||
files: |
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
bin/*
|
|
||||||
fail_on_unmatched_files: true
|
- name: Run GoReleaser (binaries + deb/rpm/apk)
|
||||||
draft: true
|
uses: goreleaser/goreleaser-action@v6
|
||||||
body: |
|
with:
|
||||||
## Container Images
|
version: 2.14.0
|
||||||
- GHCR: `${{ env.GHCR_REF }}`
|
args: release --clean
|
||||||
- Docker Hub: `${{ env.DH_REF || 'N/A' }}`
|
env:
|
||||||
**Digest:** `${{ steps.build.outputs.digest }}`
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
20
.github/workflows/mirror.yaml
vendored
20
.github/workflows/mirror.yaml
vendored
@@ -1,20 +1,28 @@
|
|||||||
name: Mirror & Sign (Docker Hub to GHCR)
|
name: Mirror & Sign (Docker Hub to GHCR)
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch: {}
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
source_image:
|
||||||
|
description: "Source image (e.g., docker.io/owner/newt)"
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
dest_image:
|
||||||
|
description: "Destination image (e.g., ghcr.io/owner/newt)"
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
packages: write
|
packages: write
|
||||||
id-token: write # for keyless OIDC
|
id-token: write # for keyless OIDC
|
||||||
|
|
||||||
env:
|
|
||||||
SOURCE_IMAGE: docker.io/fosrl/newt
|
|
||||||
DEST_IMAGE: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
mirror-and-dual-sign:
|
mirror-and-dual-sign:
|
||||||
runs-on: amd64-runner
|
runs-on: ubuntu-24.04
|
||||||
|
env:
|
||||||
|
SOURCE_IMAGE: ${{ inputs.source_image }}
|
||||||
|
DEST_IMAGE: ${{ inputs.dest_image }}
|
||||||
steps:
|
steps:
|
||||||
- name: Install skopeo + jq
|
- name: Install skopeo + jq
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
64
.github/workflows/publish-apt.yml
vendored
Normal file
64
.github/workflows/publish-apt.yml
vendored
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
name: Publish APT repo to S3/CloudFront
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [published]
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "[0-9]+.[0-9]+.[0-9]+"
|
||||||
|
- "[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+"
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
tag:
|
||||||
|
description: "Tag to publish (e.g. 1.9.0). Leave empty to use latest release."
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
backfill_all:
|
||||||
|
description: "Build/publish repo for ALL releases."
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
|
type: boolean
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
id-token: write
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
publish:
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
env:
|
||||||
|
PKG_NAME: newt
|
||||||
|
SUITE: stable
|
||||||
|
COMPONENT: main
|
||||||
|
REPO_BASE_URL: https://repo.dev.fosrl.io/apt
|
||||||
|
|
||||||
|
AWS_REGION: ${{ vars.AWS_REGION }}
|
||||||
|
S3_BUCKET: ${{ vars.S3_BUCKET }}
|
||||||
|
S3_PREFIX: ${{ vars.S3_PREFIX }}
|
||||||
|
CLOUDFRONT_DISTRIBUTION_ID: ${{ vars.CLOUDFRONT_DISTRIBUTION_ID }}
|
||||||
|
|
||||||
|
INPUT_TAG: ${{ inputs.tag }}
|
||||||
|
BACKFILL_ALL: ${{ inputs.backfill_all }}
|
||||||
|
EVENT_TAG: ${{ github.event.release.tag_name }}
|
||||||
|
PUSH_TAG: ${{ github.ref_name }}
|
||||||
|
GH_REPO: ${{ github.repository }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Configure AWS credentials (OIDC)
|
||||||
|
uses: aws-actions/configure-aws-credentials@v4
|
||||||
|
with:
|
||||||
|
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
|
||||||
|
aws-region: ${{ vars.AWS_REGION }}
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: sudo apt-get update && sudo apt-get install -y dpkg-dev apt-utils gnupg curl jq gh
|
||||||
|
|
||||||
|
- name: Publish APT repo
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
APT_GPG_PRIVATE_KEY: ${{ secrets.APT_GPG_PRIVATE_KEY }}
|
||||||
|
APT_GPG_PASSPHRASE: ${{ secrets.APT_GPG_PASSPHRASE }}
|
||||||
|
run: ./scripts/publish-apt.sh
|
||||||
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -16,7 +16,7 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
target:
|
target:
|
||||||
- local
|
- local
|
||||||
- docker-build
|
#- docker-build
|
||||||
- go-build-release-darwin-amd64
|
- go-build-release-darwin-amd64
|
||||||
- go-build-release-darwin-arm64
|
- go-build-release-darwin-arm64
|
||||||
- go-build-release-freebsd-amd64
|
- go-build-release-freebsd-amd64
|
||||||
|
|||||||
52
.goreleaser.yaml
Normal file
52
.goreleaser.yaml
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
version: 2
|
||||||
|
project_name: newt
|
||||||
|
|
||||||
|
release:
|
||||||
|
draft: true
|
||||||
|
prerelease: "{{ contains .Tag \"-rc.\" }}"
|
||||||
|
name_template: "{{ .Tag }}"
|
||||||
|
|
||||||
|
builds:
|
||||||
|
- id: newt
|
||||||
|
main: ./main.go
|
||||||
|
binary: newt
|
||||||
|
env:
|
||||||
|
- CGO_ENABLED=0
|
||||||
|
goos:
|
||||||
|
- linux
|
||||||
|
goarch:
|
||||||
|
- amd64
|
||||||
|
- arm64
|
||||||
|
flags:
|
||||||
|
- -trimpath
|
||||||
|
ldflags:
|
||||||
|
- -s -w -X main.newtVersion={{ .Tag }}
|
||||||
|
|
||||||
|
archives:
|
||||||
|
- id: binaries
|
||||||
|
builds:
|
||||||
|
- newt
|
||||||
|
format: binary
|
||||||
|
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
|
||||||
|
|
||||||
|
checksum:
|
||||||
|
name_template: "checksums.txt"
|
||||||
|
|
||||||
|
nfpms:
|
||||||
|
- id: packages
|
||||||
|
package_name: newt
|
||||||
|
builds:
|
||||||
|
- newt
|
||||||
|
vendor: fosrl
|
||||||
|
maintainer: fosrl <repo@fosrl.io>
|
||||||
|
description: Newt - userspace tunnel client and TCP/UDP proxy
|
||||||
|
license: AGPL-3.0-or-later
|
||||||
|
formats:
|
||||||
|
- deb
|
||||||
|
- rpm
|
||||||
|
- apk
|
||||||
|
bindir: /usr/bin
|
||||||
|
file_name_template: "newt_{{ .Version }}_{{ .Arch }}"
|
||||||
|
contents:
|
||||||
|
- src: LICENSE
|
||||||
|
dst: /usr/share/doc/newt/LICENSE
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
# FROM golang:1.25-alpine AS builder
|
FROM golang:1.25-alpine AS builder
|
||||||
FROM public.ecr.aws/docker/library/golang:1.25-alpine AS builder
|
|
||||||
|
|
||||||
# Install git and ca-certificates
|
# Install git and ca-certificates
|
||||||
RUN apk --no-cache add ca-certificates git tzdata
|
RUN apk --no-cache add ca-certificates git tzdata
|
||||||
@@ -19,7 +18,7 @@ COPY . .
|
|||||||
# Build the application
|
# Build the application
|
||||||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /newt
|
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /newt
|
||||||
|
|
||||||
FROM public.ecr.aws/docker/library/alpine:3.23 AS runner
|
FROM alpine:3.23 AS runner
|
||||||
|
|
||||||
RUN apk --no-cache add ca-certificates tzdata iputils
|
RUN apk --no-cache add ca-certificates tzdata iputils
|
||||||
|
|
||||||
|
|||||||
13
README.md
13
README.md
@@ -1,15 +1,24 @@
|
|||||||
# Newt
|
# Newt
|
||||||
|
|
||||||
[](https://pkg.go.dev/github.com/fosrl/newt)
|
[](https://pkg.go.dev/github.com/fosrl/newt)
|
||||||
[](https://github.com/fosrl/newt/blob/main/LICENSE)
|
[](https://github.com/fosrl/newt/blob/main/LICENSE)
|
||||||
[](https://goreportcard.com/report/github.com/fosrl/newt)
|
[](https://goreportcard.com/report/github.com/fosrl/newt)
|
||||||
|
|
||||||
Newt is a fully user space [WireGuard](https://www.wireguard.com/) tunnel client and TCP/UDP proxy, designed to securely expose private resources controlled by Pangolin. By using Newt, you don't need to manage complex WireGuard tunnels and NATing.
|
Newt is a fully user space [WireGuard](https://www.wireguard.com/) tunnel client and TCP/UDP proxy, designed to securely expose private resources controlled by Pangolin. By using Newt, you don't need to manage complex WireGuard tunnels and NATing.
|
||||||
|
|
||||||
### Installation and Documentation
|
## Installation and Documentation
|
||||||
|
|
||||||
Newt is used with Pangolin and Gerbil as part of the larger system. See documentation below:
|
Newt is used with Pangolin and Gerbil as part of the larger system. See documentation below:
|
||||||
|
|
||||||
- [Full Documentation](https://docs.pangolin.net/manage/sites/understanding-sites)
|
- [Full Documentation](https://docs.pangolin.net/manage/sites/understanding-sites)
|
||||||
|
|
||||||
|
### Install via APT (Debian/Ubuntu)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -fsSL https://repo.dev.fosrl.io/apt/public.key | sudo gpg --dearmor -o /usr/share/keyrings/newt-archive-keyring.gpg
|
||||||
|
echo "deb [signed-by=/usr/share/keyrings/newt-archive-keyring.gpg] https://repo.dev.fosrl.io/apt stable main" | sudo tee /etc/apt/sources.list.d/newt.list
|
||||||
|
sudo apt update && sudo apt install newt
|
||||||
|
```
|
||||||
|
|
||||||
## Key Functions
|
## Key Functions
|
||||||
|
|
||||||
|
|||||||
@@ -46,12 +46,11 @@ func startAuthDaemon(ctx context.Context) error {
|
|||||||
|
|
||||||
// Create auth daemon server
|
// Create auth daemon server
|
||||||
cfg := authdaemon.Config{
|
cfg := authdaemon.Config{
|
||||||
DisableHTTPS: true, // We run without HTTP server in newt
|
DisableHTTPS: true, // We run without HTTP server in newt
|
||||||
PresharedKey: "this-key-is-not-used", // Not used in embedded mode, but set to non-empty to satisfy validation
|
PresharedKey: "this-key-is-not-used", // Not used in embedded mode, but set to non-empty to satisfy validation
|
||||||
PrincipalsFilePath: principalsFile,
|
PrincipalsFilePath: principalsFile,
|
||||||
CACertPath: caCertPath,
|
CACertPath: caCertPath,
|
||||||
Force: true,
|
Force: true,
|
||||||
GenerateRandomPassword: authDaemonGenerateRandomPassword,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
srv, err := authdaemon.NewServer(cfg)
|
srv, err := authdaemon.NewServer(cfg)
|
||||||
@@ -73,6 +72,8 @@ func startAuthDaemon(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// runPrincipalsCmd executes the principals subcommand logic
|
// runPrincipalsCmd executes the principals subcommand logic
|
||||||
func runPrincipalsCmd(args []string) {
|
func runPrincipalsCmd(args []string) {
|
||||||
opts := struct {
|
opts := struct {
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import (
|
|||||||
// ProcessConnection runs the same logic as POST /connection: CA cert, user create/reconcile, principals.
|
// ProcessConnection runs the same logic as POST /connection: CA cert, user create/reconcile, principals.
|
||||||
// Use this when DisableHTTPS is true (e.g. embedded in Newt) instead of calling the API.
|
// Use this when DisableHTTPS is true (e.g. embedded in Newt) instead of calling the API.
|
||||||
func (s *Server) ProcessConnection(req ConnectionRequest) {
|
func (s *Server) ProcessConnection(req ConnectionRequest) {
|
||||||
logger.Info("connection: niceId=%q username=%q metadata.sudoMode=%q metadata.sudoCommands=%v metadata.homedir=%v metadata.groups=%v",
|
logger.Info("connection: niceId=%q username=%q metadata.sudo=%v metadata.homedir=%v",
|
||||||
req.NiceId, req.Username, req.Metadata.SudoMode, req.Metadata.SudoCommands, req.Metadata.Homedir, req.Metadata.Groups)
|
req.NiceId, req.Username, req.Metadata.Sudo, req.Metadata.Homedir)
|
||||||
|
|
||||||
cfg := &s.cfg
|
cfg := &s.cfg
|
||||||
if cfg.CACertPath != "" {
|
if cfg.CACertPath != "" {
|
||||||
@@ -16,7 +16,7 @@ func (s *Server) ProcessConnection(req ConnectionRequest) {
|
|||||||
logger.Warn("auth-daemon: write CA cert: %v", err)
|
logger.Warn("auth-daemon: write CA cert: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := ensureUser(req.Username, req.Metadata, s.cfg.GenerateRandomPassword); err != nil {
|
if err := ensureUser(req.Username, req.Metadata); err != nil {
|
||||||
logger.Warn("auth-daemon: ensure user: %v", err)
|
logger.Warn("auth-daemon: ensure user: %v", err)
|
||||||
}
|
}
|
||||||
if cfg.PrincipalsFilePath != "" {
|
if cfg.PrincipalsFilePath != "" {
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ package authdaemon
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"crypto/rand"
|
|
||||||
"encoding/hex"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@@ -124,73 +122,8 @@ func sudoGroup() string {
|
|||||||
return "sudo"
|
return "sudo"
|
||||||
}
|
}
|
||||||
|
|
||||||
// setRandomPassword generates a random password and sets it for username via chpasswd.
|
|
||||||
// Used when GenerateRandomPassword is true so SSH with PermitEmptyPasswords no can accept the user.
|
|
||||||
func setRandomPassword(username string) error {
|
|
||||||
b := make([]byte, 16)
|
|
||||||
if _, err := rand.Read(b); err != nil {
|
|
||||||
return fmt.Errorf("generate password: %w", err)
|
|
||||||
}
|
|
||||||
password := hex.EncodeToString(b)
|
|
||||||
cmd := exec.Command("chpasswd")
|
|
||||||
cmd.Stdin = strings.NewReader(username + ":" + password)
|
|
||||||
if out, err := cmd.CombinedOutput(); err != nil {
|
|
||||||
return fmt.Errorf("chpasswd: %w (output: %s)", err, string(out))
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
const skelDir = "/etc/skel"
|
|
||||||
|
|
||||||
// copySkelInto copies files from srcDir (e.g. /etc/skel) into dstDir (e.g. user's home).
|
|
||||||
// Only creates files that don't already exist. All created paths are chowned to uid:gid.
|
|
||||||
func copySkelInto(srcDir, dstDir string, uid, gid int) {
|
|
||||||
entries, err := os.ReadDir(srcDir)
|
|
||||||
if err != nil {
|
|
||||||
if !os.IsNotExist(err) {
|
|
||||||
logger.Warn("auth-daemon: read %s: %v", srcDir, err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, e := range entries {
|
|
||||||
name := e.Name()
|
|
||||||
src := filepath.Join(srcDir, name)
|
|
||||||
dst := filepath.Join(dstDir, name)
|
|
||||||
if e.IsDir() {
|
|
||||||
if st, err := os.Stat(dst); err == nil && st.IsDir() {
|
|
||||||
copySkelInto(src, dst, uid, gid)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err := os.MkdirAll(dst, 0755); err != nil {
|
|
||||||
logger.Warn("auth-daemon: mkdir %s: %v", dst, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err := os.Chown(dst, uid, gid); err != nil {
|
|
||||||
logger.Warn("auth-daemon: chown %s: %v", dst, err)
|
|
||||||
}
|
|
||||||
copySkelInto(src, dst, uid, gid)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if _, err := os.Stat(dst); err == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
data, err := os.ReadFile(src)
|
|
||||||
if err != nil {
|
|
||||||
logger.Warn("auth-daemon: read %s: %v", src, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err := os.WriteFile(dst, data, 0644); err != nil {
|
|
||||||
logger.Warn("auth-daemon: write %s: %v", dst, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err := os.Chown(dst, uid, gid); err != nil {
|
|
||||||
logger.Warn("auth-daemon: chown %s: %v", dst, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ensureUser creates the system user if missing, or reconciles sudo and homedir to match meta.
|
// ensureUser creates the system user if missing, or reconciles sudo and homedir to match meta.
|
||||||
func ensureUser(username string, meta ConnectionMetadata, generateRandomPassword bool) error {
|
func ensureUser(username string, meta ConnectionMetadata) error {
|
||||||
if username == "" {
|
if username == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -199,49 +132,12 @@ func ensureUser(username string, meta ConnectionMetadata, generateRandomPassword
|
|||||||
if _, ok := err.(user.UnknownUserError); !ok {
|
if _, ok := err.(user.UnknownUserError); !ok {
|
||||||
return fmt.Errorf("lookup user %s: %w", username, err)
|
return fmt.Errorf("lookup user %s: %w", username, err)
|
||||||
}
|
}
|
||||||
return createUser(username, meta, generateRandomPassword)
|
return createUser(username, meta)
|
||||||
}
|
}
|
||||||
return reconcileUser(u, meta)
|
return reconcileUser(u, meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
// desiredGroups returns the exact list of supplementary groups the user should have:
|
func createUser(username string, meta ConnectionMetadata) error {
|
||||||
// meta.Groups plus the sudo group when meta.SudoMode is "full" (deduped).
|
|
||||||
func desiredGroups(meta ConnectionMetadata) []string {
|
|
||||||
seen := make(map[string]struct{})
|
|
||||||
var out []string
|
|
||||||
for _, g := range meta.Groups {
|
|
||||||
g = strings.TrimSpace(g)
|
|
||||||
if g == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if _, ok := seen[g]; ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
seen[g] = struct{}{}
|
|
||||||
out = append(out, g)
|
|
||||||
}
|
|
||||||
if meta.SudoMode == "full" {
|
|
||||||
sg := sudoGroup()
|
|
||||||
if _, ok := seen[sg]; !ok {
|
|
||||||
out = append(out, sg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// setUserGroups sets the user's supplementary groups to exactly groups (local mirrors metadata).
|
|
||||||
// When groups is empty, clears all supplementary groups (usermod -G "").
|
|
||||||
func setUserGroups(username string, groups []string) {
|
|
||||||
list := strings.Join(groups, ",")
|
|
||||||
cmd := exec.Command("usermod", "-G", list, username)
|
|
||||||
if out, err := cmd.CombinedOutput(); err != nil {
|
|
||||||
logger.Warn("auth-daemon: usermod -G %s: %v (output: %s)", list, err, string(out))
|
|
||||||
} else {
|
|
||||||
logger.Info("auth-daemon: set %s supplementary groups to %s", username, list)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func createUser(username string, meta ConnectionMetadata, generateRandomPassword bool) error {
|
|
||||||
args := []string{"-s", "/bin/bash"}
|
args := []string{"-s", "/bin/bash"}
|
||||||
if meta.Homedir {
|
if meta.Homedir {
|
||||||
args = append(args, "-m")
|
args = append(args, "-m")
|
||||||
@@ -254,143 +150,75 @@ func createUser(username string, meta ConnectionMetadata, generateRandomPassword
|
|||||||
return fmt.Errorf("useradd %s: %w (output: %s)", username, err, string(out))
|
return fmt.Errorf("useradd %s: %w (output: %s)", username, err, string(out))
|
||||||
}
|
}
|
||||||
logger.Info("auth-daemon: created user %s (homedir=%v)", username, meta.Homedir)
|
logger.Info("auth-daemon: created user %s (homedir=%v)", username, meta.Homedir)
|
||||||
if generateRandomPassword {
|
if meta.Sudo {
|
||||||
if err := setRandomPassword(username); err != nil {
|
group := sudoGroup()
|
||||||
logger.Warn("auth-daemon: set random password for %s: %v", username, err)
|
cmd := exec.Command("usermod", "-aG", group, username)
|
||||||
|
if out, err := cmd.CombinedOutput(); err != nil {
|
||||||
|
logger.Warn("auth-daemon: usermod -aG %s %s: %v (output: %s)", group, username, err, string(out))
|
||||||
} else {
|
} else {
|
||||||
logger.Info("auth-daemon: set random password for %s (PermitEmptyPasswords no)", username)
|
logger.Info("auth-daemon: added %s to %s", username, group)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if meta.Homedir {
|
|
||||||
if u, err := user.Lookup(username); err == nil && u.HomeDir != "" {
|
|
||||||
uid, gid := mustAtoi(u.Uid), mustAtoi(u.Gid)
|
|
||||||
copySkelInto(skelDir, u.HomeDir, uid, gid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setUserGroups(username, desiredGroups(meta))
|
|
||||||
switch meta.SudoMode {
|
|
||||||
case "full":
|
|
||||||
if err := configurePasswordlessSudo(username); err != nil {
|
|
||||||
logger.Warn("auth-daemon: configure passwordless sudo for %s: %v", username, err)
|
|
||||||
}
|
|
||||||
case "commands":
|
|
||||||
if len(meta.SudoCommands) > 0 {
|
|
||||||
if err := configureSudoCommands(username, meta.SudoCommands); err != nil {
|
|
||||||
logger.Warn("auth-daemon: configure sudo commands for %s: %v", username, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
removeSudoers(username)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const sudoersFilePrefix = "90-pangolin-"
|
|
||||||
|
|
||||||
func sudoersPath(username string) string {
|
|
||||||
return filepath.Join("/etc/sudoers.d", sudoersFilePrefix+username)
|
|
||||||
}
|
|
||||||
|
|
||||||
// writeSudoersFile writes content to the user's sudoers.d file and validates with visudo.
|
|
||||||
func writeSudoersFile(username, content string) error {
|
|
||||||
sudoersFile := sudoersPath(username)
|
|
||||||
tmpFile := sudoersFile + ".tmp"
|
|
||||||
if err := os.WriteFile(tmpFile, []byte(content), 0440); err != nil {
|
|
||||||
return fmt.Errorf("write temp sudoers file: %w", err)
|
|
||||||
}
|
|
||||||
cmd := exec.Command("visudo", "-c", "-f", tmpFile)
|
|
||||||
if out, err := cmd.CombinedOutput(); err != nil {
|
|
||||||
os.Remove(tmpFile)
|
|
||||||
return fmt.Errorf("visudo validation failed: %w (output: %s)", err, string(out))
|
|
||||||
}
|
|
||||||
if err := os.Rename(tmpFile, sudoersFile); err != nil {
|
|
||||||
os.Remove(tmpFile)
|
|
||||||
return fmt.Errorf("move sudoers file: %w", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// configurePasswordlessSudo creates a sudoers.d file to allow passwordless sudo for the user.
|
|
||||||
func configurePasswordlessSudo(username string) error {
|
|
||||||
content := fmt.Sprintf("# Created by Pangolin auth-daemon\n%s ALL=(ALL) NOPASSWD:ALL\n", username)
|
|
||||||
if err := writeSudoersFile(username, content); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
logger.Info("auth-daemon: configured passwordless sudo for %s", username)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// configureSudoCommands creates a sudoers.d file allowing only the listed commands (NOPASSWD).
|
|
||||||
// Each command should be a full path (e.g. /usr/bin/systemctl).
|
|
||||||
func configureSudoCommands(username string, commands []string) error {
|
|
||||||
var b strings.Builder
|
|
||||||
b.WriteString("# Created by Pangolin auth-daemon (restricted commands)\n")
|
|
||||||
n := 0
|
|
||||||
for _, c := range commands {
|
|
||||||
c = strings.TrimSpace(c)
|
|
||||||
if c == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
fmt.Fprintf(&b, "%s ALL=(ALL) NOPASSWD: %s\n", username, c)
|
|
||||||
n++
|
|
||||||
}
|
|
||||||
if n == 0 {
|
|
||||||
return fmt.Errorf("no valid sudo commands")
|
|
||||||
}
|
|
||||||
if err := writeSudoersFile(username, b.String()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
logger.Info("auth-daemon: configured restricted sudo for %s (%d commands)", username, len(commands))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// removeSudoers removes the sudoers.d file for the user.
|
|
||||||
func removeSudoers(username string) {
|
|
||||||
sudoersFile := sudoersPath(username)
|
|
||||||
if err := os.Remove(sudoersFile); err != nil && !os.IsNotExist(err) {
|
|
||||||
logger.Warn("auth-daemon: remove sudoers for %s: %v", username, err)
|
|
||||||
} else if err == nil {
|
|
||||||
logger.Info("auth-daemon: removed sudoers for %s", username)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func mustAtoi(s string) int {
|
func mustAtoi(s string) int {
|
||||||
n, _ := strconv.Atoi(s)
|
n, _ := strconv.Atoi(s)
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
func reconcileUser(u *user.User, meta ConnectionMetadata) error {
|
func reconcileUser(u *user.User, meta ConnectionMetadata) error {
|
||||||
setUserGroups(u.Username, desiredGroups(meta))
|
group := sudoGroup()
|
||||||
switch meta.SudoMode {
|
inGroup, err := userInGroup(u.Username, group)
|
||||||
case "full":
|
if err != nil {
|
||||||
if err := configurePasswordlessSudo(u.Username); err != nil {
|
logger.Warn("auth-daemon: check group %s: %v", group, err)
|
||||||
logger.Warn("auth-daemon: configure passwordless sudo for %s: %v", u.Username, err)
|
inGroup = false
|
||||||
}
|
}
|
||||||
case "commands":
|
if meta.Sudo && !inGroup {
|
||||||
if len(meta.SudoCommands) > 0 {
|
cmd := exec.Command("usermod", "-aG", group, u.Username)
|
||||||
if err := configureSudoCommands(u.Username, meta.SudoCommands); err != nil {
|
if out, err := cmd.CombinedOutput(); err != nil {
|
||||||
logger.Warn("auth-daemon: configure sudo commands for %s: %v", u.Username, err)
|
logger.Warn("auth-daemon: usermod -aG %s %s: %v (output: %s)", group, u.Username, err, string(out))
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
removeSudoers(u.Username)
|
logger.Info("auth-daemon: added %s to %s", u.Username, group)
|
||||||
|
}
|
||||||
|
} else if !meta.Sudo && inGroup {
|
||||||
|
cmd := exec.Command("gpasswd", "-d", u.Username, group)
|
||||||
|
if out, err := cmd.CombinedOutput(); err != nil {
|
||||||
|
logger.Warn("auth-daemon: gpasswd -d %s %s: %v (output: %s)", u.Username, group, err, string(out))
|
||||||
|
} else {
|
||||||
|
logger.Info("auth-daemon: removed %s from %s", u.Username, group)
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
removeSudoers(u.Username)
|
|
||||||
}
|
}
|
||||||
if meta.Homedir && u.HomeDir != "" {
|
if meta.Homedir && u.HomeDir != "" {
|
||||||
uid, gid := mustAtoi(u.Uid), mustAtoi(u.Gid)
|
|
||||||
if st, err := os.Stat(u.HomeDir); err != nil || !st.IsDir() {
|
if st, err := os.Stat(u.HomeDir); err != nil || !st.IsDir() {
|
||||||
if err := os.MkdirAll(u.HomeDir, 0755); err != nil {
|
if err := os.MkdirAll(u.HomeDir, 0755); err != nil {
|
||||||
logger.Warn("auth-daemon: mkdir %s: %v", u.HomeDir, err)
|
logger.Warn("auth-daemon: mkdir %s: %v", u.HomeDir, err)
|
||||||
} else {
|
} else {
|
||||||
|
uid, gid := mustAtoi(u.Uid), mustAtoi(u.Gid)
|
||||||
_ = os.Chown(u.HomeDir, uid, gid)
|
_ = os.Chown(u.HomeDir, uid, gid)
|
||||||
copySkelInto(skelDir, u.HomeDir, uid, gid)
|
|
||||||
logger.Info("auth-daemon: created home %s for %s", u.HomeDir, u.Username)
|
logger.Info("auth-daemon: created home %s for %s", u.HomeDir, u.Username)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Ensure .bashrc etc. exist (e.g. home existed but was empty or skel was minimal)
|
|
||||||
copySkelInto(skelDir, u.HomeDir, uid, gid)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func userInGroup(username, groupName string) (bool, error) {
|
||||||
|
// getent group wheel returns "wheel:x:10:user1,user2"
|
||||||
|
cmd := exec.Command("getent", "group", groupName)
|
||||||
|
out, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
parts := strings.SplitN(strings.TrimSpace(string(out)), ":", 4)
|
||||||
|
if len(parts) < 4 {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
members := strings.Split(parts[3], ",")
|
||||||
|
for _, m := range members {
|
||||||
|
if strings.TrimSpace(m) == username {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ func writeCACertIfNotExists(path, contents string, force bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ensureUser returns an error on non-Linux.
|
// ensureUser returns an error on non-Linux.
|
||||||
func ensureUser(username string, meta ConnectionMetadata, generateRandomPassword bool) error {
|
func ensureUser(username string, meta ConnectionMetadata) error {
|
||||||
return errLinuxOnly
|
return errLinuxOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,8 @@ func (s *Server) registerRoutes() {
|
|||||||
|
|
||||||
// ConnectionMetadata is the metadata object in POST /connection.
|
// ConnectionMetadata is the metadata object in POST /connection.
|
||||||
type ConnectionMetadata struct {
|
type ConnectionMetadata struct {
|
||||||
SudoMode string `json:"sudoMode"` // "none" | "full" | "commands"
|
Sudo bool `json:"sudo"`
|
||||||
SudoCommands []string `json:"sudoCommands"` // used when sudoMode is "commands"
|
Homedir bool `json:"homedir"`
|
||||||
Homedir bool `json:"homedir"`
|
|
||||||
Groups []string `json:"groups"` // system groups to add the user to
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConnectionRequest is the JSON body for POST /connection.
|
// ConnectionRequest is the JSON body for POST /connection.
|
||||||
|
|||||||
@@ -27,9 +27,8 @@ type Config struct {
|
|||||||
Port int // Required when DisableHTTPS is false. Listen port for the HTTPS server. No default.
|
Port int // Required when DisableHTTPS is false. Listen port for the HTTPS server. No default.
|
||||||
PresharedKey string // Required when DisableHTTPS is false. HTTP auth (Authorization: Bearer <key> or X-Preshared-Key: <key>). No default.
|
PresharedKey string // Required when DisableHTTPS is false. HTTP auth (Authorization: Bearer <key> or X-Preshared-Key: <key>). No default.
|
||||||
CACertPath string // Required. Where to write the CA cert (e.g. /etc/ssh/ca.pem). No default.
|
CACertPath string // Required. Where to write the CA cert (e.g. /etc/ssh/ca.pem). No default.
|
||||||
Force bool // If true, overwrite existing CA cert (and other items) when content differs. Default false.
|
Force bool // If true, overwrite existing CA cert (and other items) when content differs. Default false.
|
||||||
PrincipalsFilePath string // Required. Path to the principals data file (JSON: username -> array of principals). No default.
|
PrincipalsFilePath string // Required. Path to the principals data file (JSON: username -> array of principals). No default.
|
||||||
GenerateRandomPassword bool // If true, set a random password on users when they are provisioned (for SSH PermitEmptyPasswords no).
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
|
|||||||
47
main.go
47
main.go
@@ -116,7 +116,6 @@ var (
|
|||||||
logLevel string
|
logLevel string
|
||||||
interfaceName string
|
interfaceName string
|
||||||
port uint16
|
port uint16
|
||||||
portStr string
|
|
||||||
disableClients bool
|
disableClients bool
|
||||||
updownScript string
|
updownScript string
|
||||||
dockerSocket string
|
dockerSocket string
|
||||||
@@ -137,7 +136,6 @@ var (
|
|||||||
authDaemonPrincipalsFile string
|
authDaemonPrincipalsFile string
|
||||||
authDaemonCACertPath string
|
authDaemonCACertPath string
|
||||||
authDaemonEnabled bool
|
authDaemonEnabled bool
|
||||||
authDaemonGenerateRandomPassword bool
|
|
||||||
// Build/version (can be overridden via -ldflags "-X main.newtVersion=...")
|
// Build/version (can be overridden via -ldflags "-X main.newtVersion=...")
|
||||||
newtVersion = "version_replaceme"
|
newtVersion = "version_replaceme"
|
||||||
|
|
||||||
@@ -212,12 +210,11 @@ func runNewtMain(ctx context.Context) {
|
|||||||
logLevel = os.Getenv("LOG_LEVEL")
|
logLevel = os.Getenv("LOG_LEVEL")
|
||||||
updownScript = os.Getenv("UPDOWN_SCRIPT")
|
updownScript = os.Getenv("UPDOWN_SCRIPT")
|
||||||
interfaceName = os.Getenv("INTERFACE")
|
interfaceName = os.Getenv("INTERFACE")
|
||||||
portStr = os.Getenv("PORT")
|
portStr := os.Getenv("PORT")
|
||||||
authDaemonKey = os.Getenv("AD_KEY")
|
authDaemonKey = os.Getenv("AD_KEY")
|
||||||
authDaemonPrincipalsFile = os.Getenv("AD_PRINCIPALS_FILE")
|
authDaemonPrincipalsFile = os.Getenv("AD_PRINCIPALS_FILE")
|
||||||
authDaemonCACertPath = os.Getenv("AD_CA_CERT_PATH")
|
authDaemonCACertPath = os.Getenv("AD_CA_CERT_PATH")
|
||||||
authDaemonEnabledEnv := os.Getenv("AUTH_DAEMON_ENABLED")
|
authDaemonEnabledEnv := os.Getenv("AUTH_DAEMON_ENABLED")
|
||||||
authDaemonGenerateRandomPasswordEnv := os.Getenv("AD_GENERATE_RANDOM_PASSWORD")
|
|
||||||
|
|
||||||
// Metrics/observability env mirrors
|
// Metrics/observability env mirrors
|
||||||
metricsEnabledEnv := os.Getenv("NEWT_METRICS_PROMETHEUS_ENABLED")
|
metricsEnabledEnv := os.Getenv("NEWT_METRICS_PROMETHEUS_ENABLED")
|
||||||
@@ -423,13 +420,6 @@ func runNewtMain(ctx context.Context) {
|
|||||||
authDaemonEnabled = v
|
authDaemonEnabled = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if authDaemonGenerateRandomPasswordEnv == "" {
|
|
||||||
flag.BoolVar(&authDaemonGenerateRandomPassword, "ad-generate-random-password", false, "Generate a random password for authenticated users")
|
|
||||||
} else {
|
|
||||||
if v, err := strconv.ParseBool(authDaemonGenerateRandomPasswordEnv); err == nil {
|
|
||||||
authDaemonGenerateRandomPassword = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// do a --version check
|
// do a --version check
|
||||||
version := flag.Bool("version", false, "Print the version")
|
version := flag.Bool("version", false, "Print the version")
|
||||||
@@ -1388,18 +1378,15 @@ persistent_keepalive_interval=5`, util.FixKey(privateKey.String()), util.FixKey(
|
|||||||
|
|
||||||
// Define the structure of the incoming message
|
// Define the structure of the incoming message
|
||||||
type SSHCertData struct {
|
type SSHCertData struct {
|
||||||
MessageId int `json:"messageId"`
|
MessageId int `json:"messageId"`
|
||||||
AgentPort int `json:"agentPort"`
|
AgentPort int `json:"agentPort"`
|
||||||
AgentHost string `json:"agentHost"`
|
AgentHost string `json:"agentHost"`
|
||||||
ExternalAuthDaemon bool `json:"externalAuthDaemon"`
|
CACert string `json:"caCert"`
|
||||||
CACert string `json:"caCert"`
|
Username string `json:"username"`
|
||||||
Username string `json:"username"`
|
NiceID string `json:"niceId"`
|
||||||
NiceID string `json:"niceId"`
|
Metadata struct {
|
||||||
Metadata struct {
|
Sudo bool `json:"sudo"`
|
||||||
SudoMode string `json:"sudoMode"`
|
Homedir bool `json:"homedir"`
|
||||||
SudoCommands []string `json:"sudoCommands"`
|
|
||||||
Homedir bool `json:"homedir"`
|
|
||||||
Groups []string `json:"groups"`
|
|
||||||
} `json:"metadata"`
|
} `json:"metadata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1419,7 +1406,7 @@ persistent_keepalive_interval=5`, util.FixKey(privateKey.String()), util.FixKey(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if we're running the auth daemon internally
|
// Check if we're running the auth daemon internally
|
||||||
if authDaemonServer != nil && !certData.ExternalAuthDaemon { // if the auth daemon is running internally and the external auth daemon is not enabled
|
if authDaemonServer != nil {
|
||||||
// Call ProcessConnection directly when running internally
|
// Call ProcessConnection directly when running internally
|
||||||
logger.Debug("Calling internal auth daemon ProcessConnection for user %s", certData.Username)
|
logger.Debug("Calling internal auth daemon ProcessConnection for user %s", certData.Username)
|
||||||
|
|
||||||
@@ -1428,10 +1415,8 @@ persistent_keepalive_interval=5`, util.FixKey(privateKey.String()), util.FixKey(
|
|||||||
NiceId: certData.NiceID,
|
NiceId: certData.NiceID,
|
||||||
Username: certData.Username,
|
Username: certData.Username,
|
||||||
Metadata: authdaemon.ConnectionMetadata{
|
Metadata: authdaemon.ConnectionMetadata{
|
||||||
SudoMode: certData.Metadata.SudoMode,
|
Sudo: certData.Metadata.Sudo,
|
||||||
SudoCommands: certData.Metadata.SudoCommands,
|
Homedir: certData.Metadata.Homedir,
|
||||||
Homedir: certData.Metadata.Homedir,
|
|
||||||
Groups: certData.Metadata.Groups,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -1465,10 +1450,8 @@ persistent_keepalive_interval=5`, util.FixKey(privateKey.String()), util.FixKey(
|
|||||||
"niceId": certData.NiceID,
|
"niceId": certData.NiceID,
|
||||||
"username": certData.Username,
|
"username": certData.Username,
|
||||||
"metadata": map[string]interface{}{
|
"metadata": map[string]interface{}{
|
||||||
"sudoMode": certData.Metadata.SudoMode,
|
"sudo": certData.Metadata.Sudo,
|
||||||
"sudoCommands": certData.Metadata.SudoCommands,
|
"homedir": certData.Metadata.Homedir,
|
||||||
"homedir": certData.Metadata.Homedir,
|
|
||||||
"groups": certData.Metadata.Groups,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
newt.iss
2
newt.iss
@@ -32,7 +32,7 @@ DefaultGroupName={#MyAppName}
|
|||||||
DisableProgramGroupPage=yes
|
DisableProgramGroupPage=yes
|
||||||
; Uncomment the following line to run in non administrative install mode (install for current user only).
|
; Uncomment the following line to run in non administrative install mode (install for current user only).
|
||||||
;PrivilegesRequired=lowest
|
;PrivilegesRequired=lowest
|
||||||
OutputBaseFilename=newt_windows_installer
|
OutputBaseFilename=mysetup
|
||||||
SolidCompression=yes
|
SolidCompression=yes
|
||||||
WizardStyle=modern
|
WizardStyle=modern
|
||||||
; Add this to ensure PATH changes are applied and the system is prompted for a restart if needed
|
; Add this to ensure PATH changes are applied and the system is prompted for a restart if needed
|
||||||
|
|||||||
22
scripts/append-release-notes.sh
Normal file
22
scripts/append-release-notes.sh
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
: "${TAG:?}"
|
||||||
|
: "${GHCR_REF:?}"
|
||||||
|
: "${DIGEST:?}"
|
||||||
|
|
||||||
|
NOTES_FILE="$(mktemp)"
|
||||||
|
|
||||||
|
existing_body="$(gh release view "${TAG}" --json body --jq '.body')"
|
||||||
|
cat > "${NOTES_FILE}" <<EOF
|
||||||
|
${existing_body}
|
||||||
|
|
||||||
|
## Container Images
|
||||||
|
- GHCR: \`${GHCR_REF}\`
|
||||||
|
- Docker Hub: \`${DH_REF:-N/A}\`
|
||||||
|
**Digest:** \`${DIGEST}\`
|
||||||
|
EOF
|
||||||
|
|
||||||
|
gh release edit "${TAG}" --draft --notes-file "${NOTES_FILE}"
|
||||||
|
|
||||||
|
rm -f "${NOTES_FILE}"
|
||||||
11
scripts/nfpm.yaml.tmpl
Normal file
11
scripts/nfpm.yaml.tmpl
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
name: __PKG_NAME__
|
||||||
|
arch: __ARCH__
|
||||||
|
platform: linux
|
||||||
|
version: __VERSION__
|
||||||
|
section: net
|
||||||
|
priority: optional
|
||||||
|
maintainer: fosrl
|
||||||
|
description: Newt - userspace tunnel client and TCP/UDP proxy
|
||||||
|
contents:
|
||||||
|
- src: build/newt
|
||||||
|
dst: /usr/bin/newt
|
||||||
149
scripts/publish-apt.sh
Normal file
149
scripts/publish-apt.sh
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# ---- required env ----
|
||||||
|
: "${GH_REPO:?}"
|
||||||
|
: "${S3_BUCKET:?}"
|
||||||
|
: "${AWS_REGION:?}"
|
||||||
|
: "${CLOUDFRONT_DISTRIBUTION_ID:?}"
|
||||||
|
: "${PKG_NAME:?}"
|
||||||
|
: "${SUITE:?}"
|
||||||
|
: "${COMPONENT:?}"
|
||||||
|
: "${APT_GPG_PRIVATE_KEY:?}"
|
||||||
|
|
||||||
|
S3_PREFIX="${S3_PREFIX:-}"
|
||||||
|
if [[ -n "${S3_PREFIX}" && "${S3_PREFIX}" != */ ]]; then
|
||||||
|
S3_PREFIX="${S3_PREFIX}/"
|
||||||
|
fi
|
||||||
|
|
||||||
|
WORKDIR="$(pwd)"
|
||||||
|
mkdir -p repo/apt assets build
|
||||||
|
|
||||||
|
download_asset() {
|
||||||
|
local tag="$1"
|
||||||
|
local pattern="$2"
|
||||||
|
local attempts=12
|
||||||
|
|
||||||
|
for attempt in $(seq 1 "${attempts}"); do
|
||||||
|
if gh release download "${tag}" -R "${GH_REPO}" -p "${pattern}" -D assets; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
echo "Asset ${pattern} not available yet (attempt ${attempt}/${attempts}); retrying..."
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "ERROR: Failed to download asset ${pattern} for ${tag} after ${attempts} attempts"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "${APT_GPG_PRIVATE_KEY}" | gpg --batch --import >/dev/null 2>&1 || true
|
||||||
|
|
||||||
|
KEYID="$(gpg --list-secret-keys --with-colons | awk -F: '$1=="sec"{print $5; exit}')"
|
||||||
|
if [[ -z "${KEYID}" ]]; then
|
||||||
|
echo "ERROR: No GPG secret key available after import."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Determine which tags to process
|
||||||
|
TAGS=""
|
||||||
|
if [[ "${BACKFILL_ALL:-false}" == "true" ]]; then
|
||||||
|
echo "Backfill mode: collecting all release tags..."
|
||||||
|
TAGS="$(gh release list -R "${GH_REPO}" --limit 200 --json tagName --jq '.[].tagName')"
|
||||||
|
else
|
||||||
|
if [[ -n "${INPUT_TAG:-}" ]]; then
|
||||||
|
TAGS="${INPUT_TAG}"
|
||||||
|
elif [[ -n "${EVENT_TAG:-}" ]]; then
|
||||||
|
TAGS="${EVENT_TAG}"
|
||||||
|
elif [[ -n "${PUSH_TAG:-}" ]]; then
|
||||||
|
TAGS="${PUSH_TAG}"
|
||||||
|
else
|
||||||
|
echo "No tag provided; using latest release tag..."
|
||||||
|
TAGS="$(gh release view -R "${GH_REPO}" --json tagName --jq '.tagName')"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Tags to process:"
|
||||||
|
printf '%s\n' "${TAGS}"
|
||||||
|
|
||||||
|
# Pull existing repo from S3 so we keep older versions
|
||||||
|
echo "Sync existing repo from S3..."
|
||||||
|
aws s3 sync "s3://${S3_BUCKET}/${S3_PREFIX}apt/" repo/apt/ >/dev/null 2>&1 || true
|
||||||
|
|
||||||
|
# Build and add packages
|
||||||
|
while IFS= read -r TAG; do
|
||||||
|
[[ -z "${TAG}" ]] && continue
|
||||||
|
echo "=== Processing tag: ${TAG} ==="
|
||||||
|
|
||||||
|
rm -rf assets build
|
||||||
|
mkdir -p assets build
|
||||||
|
|
||||||
|
deb_amd64="${PKG_NAME}_${TAG}_amd64.deb"
|
||||||
|
deb_arm64="${PKG_NAME}_${TAG}_arm64.deb"
|
||||||
|
|
||||||
|
download_asset "${TAG}" "${deb_amd64}"
|
||||||
|
download_asset "${TAG}" "${deb_arm64}"
|
||||||
|
|
||||||
|
if [[ ! -f "assets/${deb_amd64}" ]]; then
|
||||||
|
echo "ERROR: Missing release asset: ${deb_amd64}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [[ ! -f "assets/${deb_arm64}" ]]; then
|
||||||
|
echo "ERROR: Missing release asset: ${deb_arm64}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "repo/apt/pool/${COMPONENT}/${PKG_NAME:0:1}/${PKG_NAME}/"
|
||||||
|
cp -v assets/*.deb "repo/apt/pool/${COMPONENT}/${PKG_NAME:0:1}/${PKG_NAME}/"
|
||||||
|
|
||||||
|
done <<< "${TAGS}"
|
||||||
|
|
||||||
|
# Regenerate metadata
|
||||||
|
cd repo/apt
|
||||||
|
|
||||||
|
for arch in amd64 arm64; do
|
||||||
|
mkdir -p "dists/${SUITE}/${COMPONENT}/binary-${arch}"
|
||||||
|
dpkg-scanpackages -a "${arch}" pool > "dists/${SUITE}/${COMPONENT}/binary-${arch}/Packages"
|
||||||
|
gzip -fk "dists/${SUITE}/${COMPONENT}/binary-${arch}/Packages"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Release file with hashes
|
||||||
|
cat > apt-ftparchive.conf <<EOF
|
||||||
|
APT::FTPArchive::Release::Origin "fosrl";
|
||||||
|
APT::FTPArchive::Release::Label "newt";
|
||||||
|
APT::FTPArchive::Release::Suite "${SUITE}";
|
||||||
|
APT::FTPArchive::Release::Codename "${SUITE}";
|
||||||
|
APT::FTPArchive::Release::Architectures "amd64 arm64";
|
||||||
|
APT::FTPArchive::Release::Components "${COMPONENT}";
|
||||||
|
APT::FTPArchive::Release::Description "Newt APT repository";
|
||||||
|
EOF
|
||||||
|
|
||||||
|
apt-ftparchive -c apt-ftparchive.conf release "dists/${SUITE}" > "dists/${SUITE}/Release"
|
||||||
|
|
||||||
|
# Sign Release
|
||||||
|
cd "dists/${SUITE}"
|
||||||
|
|
||||||
|
gpg --batch --yes --pinentry-mode loopback \
|
||||||
|
${APT_GPG_PASSPHRASE:+--passphrase "${APT_GPG_PASSPHRASE}"} \
|
||||||
|
--local-user "${KEYID}" \
|
||||||
|
--clearsign -o InRelease Release
|
||||||
|
|
||||||
|
gpg --batch --yes --pinentry-mode loopback \
|
||||||
|
${APT_GPG_PASSPHRASE:+--passphrase "${APT_GPG_PASSPHRASE}"} \
|
||||||
|
--local-user "${KEYID}" \
|
||||||
|
-abs -o Release.gpg Release
|
||||||
|
|
||||||
|
# Export public key into apt repo root
|
||||||
|
cd ../../..
|
||||||
|
gpg --batch --yes --armor --export "${KEYID}" > "${WORKDIR}/repo/apt/public.key"
|
||||||
|
|
||||||
|
# Upload to S3
|
||||||
|
echo "Uploading to S3..."
|
||||||
|
aws s3 sync "${WORKDIR}/repo/apt" "s3://${S3_BUCKET}/${S3_PREFIX}apt/" --delete
|
||||||
|
|
||||||
|
# Invalidate metadata
|
||||||
|
echo "CloudFront invalidation..."
|
||||||
|
aws cloudfront create-invalidation \
|
||||||
|
--distribution-id "${CLOUDFRONT_DISTRIBUTION_ID}" \
|
||||||
|
--paths "/${S3_PREFIX}apt/dists/*" "/${S3_PREFIX}apt/public.key"
|
||||||
|
|
||||||
|
echo "Done. Repo base: ${REPO_BASE_URL}"
|
||||||
Reference in New Issue
Block a user