Skip to content

Commit 4b9fecd

Browse files
authored
Merge pull request #212 from aojea/substrate
feat: implement OIDC PKCE redirect flow and deploy local Dex sandbox
2 parents 269511b + d239519 commit 4b9fecd

19 files changed

Lines changed: 2684 additions & 53 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: sam-console-${ENV_NAME}
5+
namespace: ${NAMESPACE}
6+
spec:
7+
ports:
8+
- port: 8081
9+
targetPort: 8081
10+
protocol: TCP
11+
name: http
12+
selector:
13+
app: sam-console-${ENV_NAME}
14+
---
15+
apiVersion: apps/v1
16+
kind: Deployment
17+
metadata:
18+
name: sam-console-${ENV_NAME}
19+
namespace: ${NAMESPACE}
20+
spec:
21+
replicas: 1
22+
selector:
23+
matchLabels:
24+
app: sam-console-${ENV_NAME}
25+
template:
26+
metadata:
27+
labels:
28+
app: sam-console-${ENV_NAME}
29+
spec:
30+
containers:
31+
- name: sam-console
32+
image: ${IMAGE_PREFIX}sam-console:${TAG}
33+
imagePullPolicy: IfNotPresent
34+
args:
35+
- "--hub=http://sam-control-plane-${ENV_NAME}:8080"
36+
- "--bind-addr=:8081"
37+
- "--static-dir=/app/public"
38+
- "--admin-token=$(SAM_ADMIN_TOKEN)"
39+
env:
40+
- name: SAM_ADMIN_TOKEN
41+
valueFrom:
42+
secretKeyRef:
43+
name: sam-admin-token
44+
key: token
45+
ports:
46+
- containerPort: 8081
47+
resources:
48+
requests:
49+
cpu: 10m
50+
memory: 32Mi
51+
limits:
52+
cpu: 100m
53+
memory: 128Mi

Dockerfile.sam-console

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM golang:1.26.4-alpine AS builder
2+
3+
WORKDIR /src
4+
COPY go.mod go.sum ./
5+
RUN go mod download
6+
7+
COPY . .
8+
RUN CGO_ENABLED=0 go build -o /bin/sam-console ./cmd/sam-console
9+
10+
FROM gcr.io/distroless/static-debian12
11+
12+
WORKDIR /app
13+
COPY --from=builder /bin/sam-console /usr/local/bin/sam-console
14+
COPY cmd/sam-console/public /app/public
15+
16+
EXPOSE 8081
17+
ENTRYPOINT ["/usr/local/bin/sam-console"]

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ build: $(OUT_DIR)/libinterceptor.so
3131
go build -v -o "$(OUT_DIR)/mcp-client" ./cmd/mcp-client
3232
go build -v -o "$(OUT_DIR)/nano-init" ./cmd/nano-init
3333
go build -v -o "$(OUT_DIR)/sam-box" ./cmd/sam-box
34+
go build -v -o "$(OUT_DIR)/sam-console" ./cmd/sam-console
3435

3536

3637
.PHONY: mobile-ffi-host mobile-ffi-android mobile-ffi-android-x86_64 mobile-ffi-ios mobile-ffi mobile-app-apk mobile-app-apk-emulator
@@ -182,6 +183,9 @@ docker-build-nano-init:
182183
docker-build-sam-box:
183184
docker build --load -t sam-box:local -f Dockerfile.sam-box .
184185

185-
docker-build: docker-build-control-plane docker-build-router docker-build-node docker-build-mock-oidc docker-build-e2e-runtime docker-build-nano-init docker-build-sam-box
186+
docker-build-sam-console:
187+
docker build --load -t sam-console:local -f Dockerfile.sam-console .
186188

187-
.PHONY: docker-build-control-plane docker-build-router docker-build-node docker-build-mock-oidc docker-build-e2e-runtime docker-build-nano-init docker-build-sam-box docker-build
189+
docker-build: docker-build-control-plane docker-build-router docker-build-node docker-build-mock-oidc docker-build-e2e-runtime docker-build-nano-init docker-build-sam-box docker-build-sam-console
190+
191+
.PHONY: docker-build-control-plane docker-build-router docker-build-node docker-build-mock-oidc docker-build-e2e-runtime docker-build-nano-init docker-build-sam-box docker-build-sam-console docker-build

cmd/sam-console/main.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"flag"
6+
"log"
7+
"net/http"
8+
"os"
9+
"os/signal"
10+
"syscall"
11+
"time"
12+
13+
"github.com/google/sam/internal/console"
14+
)
15+
16+
func main() {
17+
var (
18+
hubURL = flag.String("hub", "http://localhost:8080", "URL of the SAM control plane")
19+
adminToken = flag.String("admin-token", "", "Admin token for control plane authentication")
20+
bindAddr = flag.String("bind-addr", ":8081", "Address to bind the console server")
21+
staticDir = flag.String("static-dir", "public", "Directory containing static frontend files")
22+
)
23+
flag.Parse()
24+
25+
if *adminToken == "" {
26+
log.Fatal("Admin token is required (via --admin-token)")
27+
}
28+
29+
srv, err := console.NewServer(console.Config{
30+
HubURL: *hubURL,
31+
AdminToken: *adminToken,
32+
StaticDir: *staticDir,
33+
})
34+
if err != nil {
35+
log.Fatalf("Failed to initialize console server: %v", err)
36+
}
37+
38+
httpSrv := &http.Server{
39+
Addr: *bindAddr,
40+
Handler: srv.Handler(),
41+
}
42+
43+
go func() {
44+
log.Printf("SAM Console listening on %s", *bindAddr)
45+
if err := httpSrv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
46+
log.Fatalf("Console server error: %v", err)
47+
}
48+
}()
49+
50+
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
51+
defer stop()
52+
53+
<-ctx.Done()
54+
log.Println("Shutting down console server...")
55+
56+
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
57+
defer cancel()
58+
if err := httpSrv.Shutdown(shutdownCtx); err != nil {
59+
log.Fatalf("Server shutdown failed: %v", err)
60+
}
61+
}

0 commit comments

Comments
 (0)