mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-27 15:49:58 +00:00
AUTH-3455: Generate short-lived ssh cert per hostname
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/go-oidc/jose"
|
||||
@@ -51,8 +52,8 @@ type errorResponse struct {
|
||||
var mockRequest func(url, contentType string, body io.Reader) (*http.Response, error) = nil
|
||||
|
||||
// GenerateShortLivedCertificate generates and stores a keypair for short lived certs
|
||||
func GenerateShortLivedCertificate(appInfo *cfpath.AppInfo, token string) error {
|
||||
fullName, err := cfpath.GenerateAppTokenFilePathFromURL(appInfo.AppDomain, appInfo.AppAUD, keyName)
|
||||
func GenerateShortLivedCertificate(appURL *url.URL, token string) error {
|
||||
fullName, err := cfpath.GenerateSSHCertFilePathFromURL(appURL, keyName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -9,7 +9,9 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -32,11 +34,12 @@ type signingArguments struct {
|
||||
}
|
||||
|
||||
func TestCertGenSuccess(t *testing.T) {
|
||||
appInfo := &cfpath.AppInfo{AppAUD: "abcd1234", AppDomain: "mySite.com"}
|
||||
url, _ := url.Parse("https://cf-test-access.com/testpath")
|
||||
token := tokenGenerator()
|
||||
|
||||
fullName, err := cfpath.GenerateAppTokenFilePathFromURL(appInfo.AppDomain, appInfo.AppAUD, keyName)
|
||||
fullName, err := cfpath.GenerateSSHCertFilePathFromURL(url, keyName)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, strings.HasSuffix(fullName, "/cf-test-access.com-testpath-cf_key"))
|
||||
|
||||
pubKeyName := fullName + ".pub"
|
||||
certKeyName := fullName + "-cert.pub"
|
||||
@@ -65,7 +68,7 @@ func TestCertGenSuccess(t *testing.T) {
|
||||
return w.Result(), nil
|
||||
}
|
||||
|
||||
err = GenerateShortLivedCertificate(appInfo, token)
|
||||
err = GenerateShortLivedCertificate(url, token)
|
||||
assert.NoError(t, err)
|
||||
|
||||
exist, err := config.FileExists(fullName)
|
||||
|
Reference in New Issue
Block a user