Skip to content

Commit

Permalink
feat(api): use tls when running locally (#405)
Browse files Browse the repository at this point in the history
Co-authored-by: Tristan Holaday <40547442+TristanHoladay@users.noreply.github.com>
  • Loading branch information
UncleGedd and TristanHoladay authored Oct 1, 2024
1 parent f65ec88 commit d4764eb
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 31 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ tmp/

*.pem
.github/test-infra/**/.terraform*

# Allow certs in hack/certs
!hack/certs/cert.pem
!hack/certs/key.pem
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repos:
args:
- "--allow-missing-credentials"
- id: detect-private-key
exclude: 'hack/certs/key.pem'
- id: end-of-file-fixer
exclude_types:
- json
Expand Down
5 changes: 5 additions & 0 deletions hack/certs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Certs

The certs in this directory are primarily used for dev'ing on UDS with HTTPS. They are also being used to enable TLS when running UDS Runtime locally (such as when doing `uds ui`).

The certs are not sensitive and were taken from the UDS Core repo [here](https://github.com/defenseunicorns/uds-core/blob/main/src/istio/values/config-tenant.yaml); specifically these are the default certs for the Istio tenant gateway.
102 changes: 102 additions & 0 deletions hack/certs/cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
-----BEGIN CERTIFICATE-----
MIIGJTCCBQ2gAwIBAgIRAOdpAaehw6DVJ36q7EuGM6owDQYJKoZIhvcNAQELBQAw
gY8xCzAJBgNVBAYTAkdCMRswGQYDVQQIExJHcmVhdGVyIE1hbmNoZXN0ZXIxEDAO
BgNVBAcTB1NhbGZvcmQxGDAWBgNVBAoTD1NlY3RpZ28gTGltaXRlZDE3MDUGA1UE
AxMuU2VjdGlnbyBSU0EgRG9tYWluIFZhbGlkYXRpb24gU2VjdXJlIFNlcnZlciBD
QTAeFw0yMzEwMTcwMDAwMDBaFw0y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s9UgOHYm8Cd8rID
ZsswDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQFMAMBAf8wEQYDVR0gBAowCDAG
BgRVHSAAMEMGA1UdHwQ8MDowOKA2oDSGMmh0dHA6Ly9jcmwuY29tb2RvY2EuY29t
L0FBQUNlcnRpZmljYXRlU2VydmljZXMuY3JsMDQGCCsGAQUFBwEBBCgwJjAkBggr
BgEFBQcwAYYYaHR0cDovL29jc3AuY29tb2RvY2EuY29tMA0GCSqGSIb3DQEBDAUA
A4IBAQAYh1HcdCE9nIrgJ7cz0C7M7PDmy14R3iJvm3WOnnL+5Nb+qh+cli3vA0p+
rvSNb3I8QzvAP+u431yqqcau8vzY7qN7Q/aGNnwU4M309z/+3ri0ivCRlv79Q2R+
/czSAaF9ffgZGclCKxO/WIu6pKJmBHaIkU4MiRTOok3JMrO66BQavHHxW/BBC5gA
CiIDEOUMsfnNkjcZ7Tvx5Dq2+UUTJnWvu6rvP3t3O9LEApE9GQDTF1w52z97GA1F
zZOFli9d31kWTz9RvdVFGD/tSo7oBmF0Ixa1DVBzJ0RHfxBdiSprhTEUxOipakyA
vGp4z7h/jnZymQyd/teRCBaho1+V
-----END CERTIFICATE-----
28 changes: 28 additions & 0 deletions hack/certs/key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCYIUnv69aiBu0X
hp8CMGVXNowUccaQnbzGDkc+uqZSpv/fvX9FHdMXMpn1GixlnvZNr3nkQT22OhiR
8o3cbqf7DKWglgS2O755qKaHSpp87BmPX4+PM8QQrxAoZspSN+R2/L8qGJYS/pO5
JWRDiR216A1tqUJwboLYb1bmZpnJJBoVh48r9peYH+UgyUUK7D2OygL/hMa+2bvf
g7JuGAAkoxe12cL9xVZdDG0IbWxU5EDdEUhvMk2fC0xQsrwtx24dvdbv3MqPr6lM
Fn2whmJNxiZKOMY/G3Zeqoo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9+OE5
FaENtH/APeTZ6Xojrzj3ESV4LH/aVz6TL/aMAfVxAoGBAKSiEif4b+M7pSo95fzJ
xjzp03hkcZ0JreU1DOyIZi9hfttgzvkLnI+KN82500fFhNGndXsWFDC5tYHQmFCh
UEX4Co+Z1iGEfi3KRMarb90LhMJziaUmT9Ufa/DiuoklwgP+v6DqdBB0zhMzDZBz
YyfzHvCdJsBCP0WYvMqaejeO
-----END PRIVATE KEY-----
44 changes: 39 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"crypto/tls"
"embed"
"log"
"net/http"
Expand All @@ -13,18 +14,51 @@ import (
//go:embed ui/build/*
var assets embed.FS

//go:embed hack/certs/cert.pem
var localCert []byte

//go:embed hack/certs/key.pem
var localKey []byte

func main() {
message.SetLogLevel(message.DebugLevel)
r, err := api.Setup(&assets)

r, inCluster, err := api.Setup(&assets)
if err != nil {
// Log the error and exit
message.WarnErr(err, "failed to start the API server")
os.Exit(1)
}
log.Println("Starting server on :8080")

//nolint:gosec,govet
if err = http.ListenAndServe(":8080", r); err != nil {
message.WarnErrf(err, "server failed to start: %s", err.Error())
os.Exit(1)
if inCluster {
log.Println("Starting server on :8080")

if err = http.ListenAndServe(":8080", r); err != nil {
message.WarnErrf(err, "server failed to start: %s", err.Error())
os.Exit(1)
}
} else {
// create tls config from embedded cert and key
cert, err := tls.X509KeyPair(localCert, localKey)
if err != nil {
log.Fatalf("Failed to load embedded certificate: %v", err)
}
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{cert},
}

// Create a server with TLS config
server := &http.Server{
Addr: ":8443",
Handler: r,
TLSConfig: tlsConfig,
}

log.Println("Starting server on :8443")
if err = server.ListenAndServeTLS("", ""); err != nil {
message.WarnErrf(err, "server failed to start: %s", err.Error())
os.Exit(1)
}
}
}
42 changes: 24 additions & 18 deletions pkg/api/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,28 @@ type K8sResources struct {
cancel context.CancelFunc
}

// Setup initializes the API server with the given assets
// It returns the chi router, a boolean indicating if the server is running in cluster, and an error if any
// @title UDS Runtime API
// @version 0.0.0
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @BasePath /api/v1
// @schemes http https
func Setup(assets *embed.FS) (*chi.Mux, error) {
apiAuth, token, err := checkForLocalAuth()
func Setup(assets *embed.FS) (*chi.Mux, bool, error) {
var apiAuth bool
var token string

inCluster, err := isRunningInCluster()
if err != nil {
return nil, fmt.Errorf("failed to set auth: %w", err)
return nil, inCluster, fmt.Errorf("failed to check if running in cluster: %w", err)
}

if !inCluster {
apiAuth, token, err = checkForLocalAuth()
if err != nil {
return nil, inCluster, fmt.Errorf("failed to set auth: %w", err)
}
}

authSVC := checkForClusterAuth()
Expand All @@ -73,24 +85,18 @@ func Setup(assets *embed.FS) (*chi.Mux, error) {
// Setup k8s resources
k8sResources, err := setupK8sResources()
if err != nil {
return nil, fmt.Errorf("failed to setup k8s resources: %w", err)
return nil, inCluster, fmt.Errorf("failed to setup k8s resources: %w", err)
}

// Create the disconnected channel
disconnected := make(chan error)

inCluster, err := isRunningInCluster()
if err != nil {
k8sResources.cancel()
return nil, fmt.Errorf("failed to check if running in cluster: %w", err)
}

// Get current k8s context and start the reconnection goroutine if NOT in cluster
if !inCluster {
currentCtx, currentCluster, err := k8s.GetCurrentContext()
if err != nil {
k8sResources.cancel()
return nil, fmt.Errorf("failed to get current context: %w", err)
return nil, inCluster, fmt.Errorf("failed to get current context: %w", err)
}

k8sResources.currentCtx = currentCtx
Expand Down Expand Up @@ -230,30 +236,30 @@ func Setup(assets *embed.FS) (*chi.Mux, error) {
})

if apiAuth {
port := "8080"
ip := "127.0.0.1"
port := "8443"
host := "runtime-local.uds.dev"
colorYellow := "\033[33m"
colorReset := "\033[0m"
url := fmt.Sprintf("http://%s:%s?token=%s", ip, port, token)
url := fmt.Sprintf("https://%s:%s?token=%s", host, port, token)
log.Printf("%sRuntime API connection: %s%s", colorYellow, url, colorReset)
err := exec.LaunchURL(url)
if err != nil {
return nil, fmt.Errorf("failed to launch URL: %w", err)
return nil, inCluster, fmt.Errorf("failed to launch URL: %w", err)
}
}

// Serve static files from embed.FS
if assets != nil {
staticFS, err := fs.Sub(assets, "ui/build")
if err != nil {
return nil, fmt.Errorf("failed to create static file system: %w", err)
return nil, inCluster, fmt.Errorf("failed to create static file system: %w", err)
}

if err := fileServer(r, http.FS(staticFS)); err != nil {
return nil, fmt.Errorf("failed to serve static files: %w", err)
return nil, inCluster, fmt.Errorf("failed to serve static files: %w", err)
}
}
return r, nil
return r, inCluster, nil
}

func setupK8sResources() (*K8sResources, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type TestRoute struct {

func setup() (*chi.Mux, error) {
os.Setenv("API_AUTH_DISABLED", "true")
r, err := api.Setup(nil)
r, _, err := api.Setup(nil)
return r, err
}

Expand Down
4 changes: 2 additions & 2 deletions ui/playwright.config.apiauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineConfig } from '@playwright/test'
import { loadEnv } from 'vite'

const { VITE_PORT_ENV } = loadEnv('dev', process.cwd())
const port = VITE_PORT_ENV ?? '8080'
const port = VITE_PORT_ENV ?? '8443'

export default defineConfig({
timeout: 60 * 1000,
Expand All @@ -11,7 +11,7 @@ export default defineConfig({
retries: 0,
testMatch: /(.+\.)?(test|spec)\.[jt]s/,
use: {
baseURL: `http://localhost:${port}/`,
baseURL: `https://runtime-local.uds.dev:${port}/`,
},
})

Expand Down
10 changes: 7 additions & 3 deletions ui/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { defineConfig } from '@playwright/test'
import { loadEnv } from 'vite'

const { VITE_PORT_ENV } = loadEnv('dev', process.cwd())
const port = VITE_PORT_ENV ?? '8080'

// use port 8443 because by default we use TLS when running locally
const port = VITE_PORT_ENV ?? '8443'
const protocol = 'https'
const host = 'runtime-local.uds.dev'

export default defineConfig({
webServer: {
command: 'API_AUTH_DISABLED=true ../build/uds-runtime',
url: `http://localhost:${port}`,
url: `${protocol}://${host}:${port}`,
reuseExistingServer: !process.env.CI,
},
timeout: 10 * 1000,
Expand All @@ -17,7 +21,7 @@ export default defineConfig({
retries: process.env.CI ? 2 : 1,
testMatch: /^(?!.*api-auth)(.+\.)?(test|spec)\.[jt]s$/,
use: {
baseURL: `http://localhost:${port}/`,
baseURL: `${protocol}://${host}:${port}/`,
},
})

Expand Down
5 changes: 3 additions & 2 deletions ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ export default defineConfig(({ mode }) => ({
server: {
proxy: {
// Proxy all requests starting with /api to the go server
// noting that we ues https and 8443 because by default we use TLS when running locally
'/api': {
target: 'http://localhost:8080',
target: 'https://runtime-local:8443',
changeOrigin: true,
},
'/health': {
target: 'http://localhost:8080',
target: 'https://runtime-local:8443',
changeOrigin: true,
},
},
Expand Down

0 comments on commit d4764eb

Please sign in to comment.