Skip to content

Commit

Permalink
tmp(acme-writer): force use of authentication env var
Browse files Browse the repository at this point in the history
  • Loading branch information
aschmahmann committed Sep 16, 2024
1 parent ae0139e commit 1f5b301
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions acme/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ func (c *acmeWriter) OnStartup() error {
authKey, found := os.LookupEnv(authEnvVar)
if found {
c.forgeAuthKey = authKey
} else {
// TODO: Remove when ready for rollout
return fmt.Errorf("environment variable %s not found", authEnvVar)
}

c.ln = ln

c.mux = mux.NewRouter()
Expand Down
10 changes: 10 additions & 0 deletions e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ import (
const forge = "libp2p.direct"
const forgeRegistration = "registration.libp2p.direct"

const authEnvVar = "FORGE_ACCESS_TOKEN"
const authToken = "testToken"

var dnsServerAddress string
var httpPort int

Expand All @@ -63,6 +66,11 @@ func TestMain(m *testing.M) {
os.Exit(1)
}

if err := os.Setenv(authEnvVar, authToken); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}

defer os.RemoveAll(tmpDir)

tmpListener, err := net.Listen("tcp", ":0")
Expand Down Expand Up @@ -138,6 +146,7 @@ func TestSetACMEChallenge(t *testing.T) {
t.Fatal(err)
}
req.Host = forgeRegistration
req.Header.Set(authEnvVar, authToken)

peerHTTPClient := &httppeeridauth.ClientPeerIDAuth{PrivKey: sk}
_, resp, err := peerHTTPClient.AuthenticatedDo(http.DefaultClient, req)
Expand Down Expand Up @@ -425,6 +434,7 @@ func TestLibp2pACMEE2E(t *testing.T) {
client.WithForgeDomain(forge), client.WithForgeRegistrationEndpoint(fmt.Sprintf("http://127.0.0.1:%d", httpPort)), client.WithCAEndpoint(acmeEndpoint), client.WithTrustedRoots(cas),
client.WithModifiedForgeRequest(func(req *http.Request) error {
req.Host = forgeRegistration
req.Header.Set(authEnvVar, authToken)
return nil
}),
client.WithAllowPrivateForgeAddrs(),
Expand Down

0 comments on commit 1f5b301

Please sign in to comment.