Skip to content

Commit

Permalink
ref(feat-33): TLS support for Spin.
Browse files Browse the repository at this point in the history
The `spin-cli` now supports the `tls-key` and `tls-crt` options, e.g.
```spin up -tls-key <path/to/key> -tls-crt <path/to/crt> ...```

For convenience, the following environment variables can be set in lieu of
their respective flags.

```
SPIN_TLS_CRT=<path/to/crt>
SPIN_TLS_KEY=<path/to/key>
```

NOTE: Explicitly set flags take precedence over the environment.

```
export RUST_LOG=spin_engine=info,spin_http,wact=info
export SPIN_TLS_CRT=crates/http/tests/local.crt.pem
export SPIN_TLS_KEY=crates/http/tests/local.key.pem
spin up --app templates/spin-http/spin.toml
curl -k https://127.0.0.1:3000/test/hello
```

Signed-off-by: Brian Hardock <brian.hardock@fermyon.com>
Co-authored-by: Michelle Dhanani <michelle@fermyon.com>
Signed-off-by: Brian Hardock <brian.hardock@fermyon.com>
  • Loading branch information
fibonacci1729 and michelleN committed Mar 1, 2022
1 parent 2d49ef8 commit 47bf88a
Show file tree
Hide file tree
Showing 10 changed files with 318 additions and 47 deletions.
44 changes: 43 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
LOG_LEVEL ?= spin=trace
CERT_NAME ?= local

.PHONY: build
build:
Expand All @@ -9,3 +10,10 @@ test:
RUST_LOG=$(LOG_LEVEL) cargo test --all -- --nocapture
cargo clippy --all-targets --all-features -- -D warnings
cargo fmt --all -- --check

# simple convenience for developing with TLS
.PHONY: tls
tls: ${CERT_NAME}.crt.pem

$(CERT_NAME).crt.pem:
openssl req -newkey rsa:2048 -nodes -keyout $(CERT_NAME).key.pem -x509 -days 365 -out $(CERT_NAME).crt.pem
5 changes: 5 additions & 0 deletions crates/http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ async-trait = "0.1"
bytes = "1.1"
ctrlc = "3.2.1"
futures = "0.3"
futures-util = "0.3.8"
http = "0.2"
hyper = { version = "0.14", features = [ "full" ] }
hyper-rustls = { version = "0.23.0" }
indexmap = "1.6"
serde = { version = "1.0", features = [ "derive" ] }
spin-config = { path = "../config" }
spin-engine = { path = "../engine" }
tls-listener = { version = "0.4.0", features = ["rustls", "hyper-h1", "hyper-h2"] }
tokio = { version = "1.10", features = [ "full" ] }
tokio-rustls = { version = "0.23.2" }
rustls-pemfile = "0.3.0"
tracing = { version = "0.1", features = [ "log" ] }
tracing-futures = "0.2"
tracing-subscriber = { version = "0.3.7", features = [ "env-filter" ] }
Expand Down
Loading

0 comments on commit 47bf88a

Please sign in to comment.