mirror of
https://github.com/juanfont/headscale.git
synced 2026-09-16 21:42:02 +09:00
util, db: generate key material as hex via tailscale rands
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/juanfont/headscale/hscontrol/util"
|
||||
"github.com/juanfont/headscale/integration/dsic"
|
||||
"github.com/juanfont/headscale/integration/hsic"
|
||||
"github.com/juanfont/headscale/integration/integrationutil"
|
||||
@@ -17,14 +16,14 @@ import (
|
||||
"tailscale.com/net/netmon"
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/types/key"
|
||||
"tailscale.com/util/rands"
|
||||
)
|
||||
|
||||
func TestDERPVerifyEndpoint(t *testing.T) {
|
||||
IntegrationSkip(t)
|
||||
|
||||
// Generate random hostname for the headscale instance
|
||||
hash, err := util.GenerateRandomStringDNSSafe(6)
|
||||
require.NoError(t, err)
|
||||
hash := rands.HexString(6)
|
||||
|
||||
testName := "derpverify"
|
||||
hostname := fmt.Sprintf("hs-%s-%s", testName, hash)
|
||||
@@ -45,7 +44,8 @@ func TestDERPVerifyEndpoint(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
defer scenario.ShutdownAssertNoPanics(t)
|
||||
|
||||
derper, err := scenario.CreateDERPServer("head",
|
||||
derper, err := scenario.CreateDERPServer(
|
||||
"head",
|
||||
dsic.WithCACert(caHeadscale),
|
||||
dsic.WithVerifyClientURL(fmt.Sprintf("https://%s/verify", net.JoinHostPort(hostname, strconv.Itoa(headscalePort)))),
|
||||
)
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/juanfont/headscale/hscontrol/util"
|
||||
"github.com/ory/dockertest/v3"
|
||||
"tailscale.com/util/rands"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -46,7 +46,7 @@ func GenerateRunID() string {
|
||||
timestamp := now.Format(TimestampFormatRunID)
|
||||
|
||||
// Add a short random hash to ensure uniqueness
|
||||
randomHash := util.MustGenerateRandomStringDNSSafe(6)
|
||||
randomHash := rands.HexString(6)
|
||||
|
||||
return fmt.Sprintf("%s-%s", timestamp, randomHash)
|
||||
}
|
||||
|
||||
@@ -11,11 +11,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/juanfont/headscale/hscontrol/util"
|
||||
"github.com/juanfont/headscale/integration/dockertestutil"
|
||||
"github.com/juanfont/headscale/integration/integrationutil"
|
||||
"github.com/ory/dockertest/v3"
|
||||
"github.com/ory/dockertest/v3/docker"
|
||||
"tailscale.com/util/rands"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -143,10 +143,7 @@ func New(
|
||||
networks []*dockertest.Network,
|
||||
opts ...Option,
|
||||
) (*DERPServerInContainer, error) {
|
||||
hash, err := util.GenerateRandomStringDNSSafe(dsicHashLength)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hash := rands.HexString(dsicHashLength)
|
||||
|
||||
// Include run ID in hostname for easier identification of which test run owns this container
|
||||
runID := dockertestutil.GetIntegrationRunID()
|
||||
|
||||
@@ -36,6 +36,7 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/util/mak"
|
||||
"tailscale.com/util/rands"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -172,7 +173,7 @@ func WithHostPortBindings(bindings map[string][]string) Option {
|
||||
// in the Docker container name.
|
||||
func WithTestName(testName string) Option {
|
||||
return func(hsic *HeadscaleInContainer) {
|
||||
hash, _ := util.GenerateRandomStringDNSSafe(hsicHashLength)
|
||||
hash := rands.HexString(hsicHashLength)
|
||||
|
||||
hostname := fmt.Sprintf("hs-%s-%s", testName, hash)
|
||||
hsic.hostname = hostname
|
||||
@@ -331,10 +332,7 @@ func New(
|
||||
networks []*dockertest.Network,
|
||||
opts ...Option,
|
||||
) (*HeadscaleInContainer, error) {
|
||||
hash, err := util.GenerateRandomStringDNSSafe(hsicHashLength)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hash := rands.HexString(hsicHashLength)
|
||||
|
||||
// Include run ID in hostname for easier identification of which test run owns this container
|
||||
runID := dockertestutil.GetIntegrationRunID()
|
||||
@@ -499,7 +497,7 @@ func New(
|
||||
// dockertest isn't very good at handling containers that has already
|
||||
// been created, this is an attempt to make sure this container isn't
|
||||
// present.
|
||||
err = pool.RemoveContainerByName(hsic.hostname)
|
||||
err := pool.RemoveContainerByName(hsic.hostname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
|
||||
"github.com/juanfont/headscale/hscontrol/capver"
|
||||
"github.com/juanfont/headscale/hscontrol/types"
|
||||
"github.com/juanfont/headscale/hscontrol/util"
|
||||
"github.com/juanfont/headscale/integration/dockertestutil"
|
||||
"github.com/juanfont/headscale/integration/dsic"
|
||||
"github.com/juanfont/headscale/integration/hsic"
|
||||
@@ -42,6 +41,7 @@ import (
|
||||
"tailscale.com/envknob"
|
||||
"tailscale.com/util/mak"
|
||||
"tailscale.com/util/multierr"
|
||||
"tailscale.com/util/rands"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -197,7 +197,7 @@ func NewScenario(spec ScenarioSpec) (*Scenario, error) {
|
||||
pool.MaxWait = spec.MaxWait
|
||||
}
|
||||
|
||||
testHashPrefix := "hs-" + util.MustGenerateRandomStringDNSSafe(scenarioHashLength)
|
||||
testHashPrefix := "hs-" + rands.HexString(scenarioHashLength)
|
||||
s := &Scenario{
|
||||
controlServers: xsync.NewMap[string, ControlServer](),
|
||||
users: make(map[string]*User),
|
||||
@@ -1571,7 +1571,7 @@ func (s *Scenario) runMockOIDC(accessTTL time.Duration, users []mockoidc.MockUse
|
||||
|
||||
portNotation := fmt.Sprintf("%d/tcp", port)
|
||||
|
||||
hash, _ := util.GenerateRandomStringDNSSafe(hsicOIDCMockHashLength)
|
||||
hash := rands.HexString(hsicOIDCMockHashLength)
|
||||
|
||||
hostname := "hs-oidcmock-" + hash
|
||||
|
||||
@@ -1679,7 +1679,7 @@ func Webservice(s *Scenario, networkName string) (*dockertest.Resource, error) {
|
||||
// log.Fatalf("finding open port: %s", err)
|
||||
// }
|
||||
// portNotation := fmt.Sprintf("%d/tcp", port)
|
||||
hash := util.MustGenerateRandomStringDNSSafe(hsicOIDCMockHashLength)
|
||||
hash := rands.HexString(hsicOIDCMockHashLength)
|
||||
|
||||
hostname := "hs-webservice-" + hash
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import (
|
||||
"tailscale.com/types/key"
|
||||
"tailscale.com/types/netmap"
|
||||
"tailscale.com/util/multierr"
|
||||
"tailscale.com/util/rands"
|
||||
"tailscale.com/wgengine/filter"
|
||||
)
|
||||
|
||||
@@ -314,10 +315,9 @@ func New(
|
||||
version string,
|
||||
opts ...Option,
|
||||
) (*TailscaleInContainer, error) {
|
||||
hash, err := util.GenerateRandomStringDNSSafe(tsicHashLength)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hash := rands.HexString(tsicHashLength)
|
||||
|
||||
var err error
|
||||
|
||||
// Include run ID in hostname for easier identification of which test run owns this container
|
||||
runID := dockertestutil.GetIntegrationRunID()
|
||||
|
||||
@@ -15,11 +15,11 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/juanfont/headscale/hscontrol/util"
|
||||
"github.com/juanfont/headscale/integration/dockertestutil"
|
||||
"github.com/juanfont/headscale/integration/integrationutil"
|
||||
"github.com/ory/dockertest/v3"
|
||||
"github.com/ory/dockertest/v3/docker"
|
||||
"tailscale.com/util/rands"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -129,7 +129,8 @@ func (t *TailscaleRustInContainer) buildEntrypoint() []string {
|
||||
|
||||
commands = append(commands, "update-ca-certificates 2>/dev/null || true")
|
||||
|
||||
commands = append(commands,
|
||||
commands = append(
|
||||
commands,
|
||||
fmt.Sprintf(`export TS_CONTROL_URL=%q`, t.headscaleURL),
|
||||
// The tailscale crate refuses to run without this env gate;
|
||||
// see lib.rs in tailscale-rs.
|
||||
@@ -151,10 +152,9 @@ func New(
|
||||
pool *dockertest.Pool,
|
||||
opts ...Option,
|
||||
) (*TailscaleRustInContainer, error) {
|
||||
hash, err := util.GenerateRandomStringDNSSafe(tsricHashLength)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hash := rands.HexString(tsricHashLength)
|
||||
|
||||
var err error
|
||||
|
||||
runID := dockertestutil.GetIntegrationRunID()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user