Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
51c2165
Say what agyn local is doing while it does it
vitramir Aug 10, 2026
810610d
Ask about the port only when it is taken, and the CA as three answers
vitramir Aug 10, 2026
81cd2ef
Carry the scripts that act on a VM, instead of the image carrying them
vitramir Aug 11, 2026
d237adc
Run gofmt over profile.go
vitramir Aug 11, 2026
8de82b7
One run log per VM, not one for the machine
vitramir Aug 11, 2026
d2b256a
Say which part of the platform the port move is on
vitramir Aug 11, 2026
ce7433d
Three steps, because these are three things
vitramir Aug 11, 2026
1419e01
Do not wait for pods that are waiting for the repair
vitramir Aug 11, 2026
12a23c5
Write the host's port into the release, not over its output
vitramir Aug 11, 2026
db8601e
Report the overlay's two upgrades, and stop paying for four JVMs
vitramir Aug 11, 2026
0af28a6
84s to 40s: stop restarting things into each other
vitramir Aug 11, 2026
5cf266f
Move a port without knowing which provider issues tokens
vitramir Aug 12, 2026
1d306ba
Close a start with the way in, not just the address
vitramir Aug 12, 2026
e72b286
A finished step ends on its summary, not its last frame
vitramir Aug 12, 2026
3ef658b
Dex's port is a chart value, not a ConfigMap to patch
vitramir Aug 12, 2026
0e54fb5
An upgrade past 0.56.0 moves the install to dex
vitramir Aug 12, 2026
499f68f
Dex's callbacks name the port this host serves
vitramir Aug 12, 2026
d6ced52
Print the address Dex authenticates by, from the ConfigMap that exists
vitramir Aug 12, 2026
af06ff6
An upgrade that changes provider says how to sign in
vitramir Aug 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
616 changes: 485 additions & 131 deletions internal/cmd/local.go

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions internal/cmd/local_ca_choice_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cmd

import (
"strings"
"testing"
)

// The picker returns a position and the caller switches on a constant, so the
// two have to agree. They disagree silently and in the worst direction: a row
// added in the wrong place installs a CA on the machine of someone who chose to
// skip, and nothing in the output would say so.
func TestCAChoiceItemsMatchTheirConstants(t *testing.T) {
items := caChoiceItems()
if len(items) != 3 {
t.Fatalf("expected three answers, got %d", len(items))
}
for _, tc := range []struct {
choice caChoice
want string
}{
{caInstall, "Install"},
{caExport, "Export"},
{caSkip, "Skip"},
} {
if !strings.HasPrefix(items[tc.choice].Label, tc.want) {
t.Errorf("choice %d is %q, want it to start with %q", tc.choice, items[tc.choice].Label, tc.want)
}
}
}

// The default answer is the one that leaves the platform usable in a browser.
func TestCAChoiceOpensOnInstall(t *testing.T) {
items := caChoiceItems()
for index, item := range items {
if item.Current && caChoice(index) != caInstall {
t.Fatalf("expected the picker to open on install, opens on %q", item.Label)
}
}
if !items[caInstall].Current {
t.Fatal("expected install to be marked as the current answer")
}
}
70 changes: 42 additions & 28 deletions internal/cmd/local_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/agynio/agyn-cli/internal/auth"
"github.com/agynio/agyn-cli/internal/config"
"github.com/agynio/agyn-cli/internal/local"
"github.com/agynio/agyn-cli/internal/terminal"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -72,7 +74,7 @@ func newLocalCredentialsCmd() *cobra.Command {
return fmt.Errorf("the VM is not running; start it with `agyn local start`")
}

return provisionLocalProfile(cmd, flags, settings.Port, true)
return provisionLocalProfile(cmd, newSteps(cmd), flags, settings.Port, true, "")
},
}

Expand All @@ -87,58 +89,70 @@ func newLocalCredentialsCmd() *cobra.Command {
//
// recordCA is false when the caller was told to leave certificates alone; the
// profile then trusts whatever the system trust store holds.
func provisionLocalProfile(cmd *cobra.Command, flags localProfileFlags, port int, recordCA bool) error {
stdout := cmd.OutOrStdout()
//
// organization is the id a caller has already read from the VM — the readiness
// wait reads it, because it is one of the two signals that the platform has
// finished starting. Empty means read it here.
func provisionLocalProfile(cmd *cobra.Command, steps *terminal.Steps, flags localProfileFlags, port int, recordCA bool, organization string) error {
name := flags.targetProfile()

token, err := localBootstrapToken(name)
if err != nil {
return err
}

profile := config.Profile{GatewayURL: local.GatewayURL(port)}
// Three steps, because these are three things. Two of them change the VM
// and take as long as the workloads they restart; the third writes a file
// on this machine. Reporting all of it as "configuring a profile" put
// minutes of cluster reconfiguration under the name of the fastest part,
// and left the overlay being moved reading as something a profile does.
step := steps.Start("Installing the Gateway bootstrap token")
if _, err := local.SetBootstrapToken(token, step.Detail); err != nil {
return step.Fail(err)
}
step.Done("")

// The image bakes a default port into the URLs it hands a browser — the
// OIDC redirects and the media proxy origin. Whenever this host forwards
// something else, signing in would bounce back to a dead port. On a
// non-default port this restarts most of the platform, so it says which
// part it is on.
step = steps.Start("Pointing the platform at port " + strconv.Itoa(port))
if _, err := local.SetIngressPort(port, step.Detail); err != nil {
return step.Fail(err)
}
step.Done("")

step = steps.Start("Configuring profile " + name)
profile := config.Profile{GatewayURL: local.GatewayURL(port), Organization: organization}
if recordCA {
// Extracted afresh rather than reused from the cache: a recreated or
// upgraded VM can carry a different CA, and a stale one fails every
// handshake with an error that looks like a network fault.
if err := local.ExtractCA(); err != nil {
return err
return step.Fail(err)
}
caFile, err := local.CAPath()
if err != nil {
return err
return step.Fail(err)
}
profile.CAFile = shortenHomePath(caFile)
}

profile.Organization, err = local.OrganizationID()
if err != nil {
return err
}

// Last of the VM work, and the only part that changes the VM: the reads
// above fail fast, while these restart workloads when a value differs.
fmt.Fprintln(stdout, "Installing the Gateway bootstrap token (restarts the gateway if it changed)...")
if _, err := local.SetBootstrapToken(token); err != nil {
return err
}

// The image bakes a default port into the URLs it hands a browser — the
// OIDC redirects and the media proxy origin. Whenever this host forwards
// something else, signing in would bounce back to a dead port.
fmt.Fprintln(stdout, "Pointing browser-facing URLs at the forwarded port...")
if _, err := local.SetIngressPort(port); err != nil {
return err
if profile.Organization == "" {
profile.Organization, err = local.OrganizationID()
if err != nil {
return step.Fail(err)
}
}

current, err := writeLocalProfile(name, profile, token)
if err != nil {
return err
return step.Fail(err)
}
step.Done("organization " + profile.Organization)

fmt.Fprintf(stdout, "Configured profile %s: %s, organization %s.\n", name, profile.GatewayURL, profile.Organization)
if current != name {
fmt.Fprintf(stdout, "Commands still run under profile %s; switch with: agyn profile use %s\n", current, name)
steps.Note(fmt.Sprintf("commands still run under profile %s; switch with: agyn profile use %s", current, name))
}
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ func newProfileRemoveCmd() *cobra.Command {
func profileOutputFor(cfg *config.Config, name, currentName string) profileOutput {
profile := cfg.Profile(name)
return profileOutput{
Name: name,
Current: name == currentName,
GatewayURL: cfg.ResolveGatewayTargetFor(name, "").URL,
Name: name,
Current: name == currentName,
GatewayURL: cfg.ResolveGatewayTargetFor(name, "").URL,
Organization: profile.Organization,
CAFile: profile.CAFile,
SandboxIdleTimeout: profile.SandboxIdleTimeout,
Expand Down
84 changes: 68 additions & 16 deletions internal/local/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@ package local

import (
"crypto/rand"
_ "embed"
"encoding/base64"
"fmt"
"strconv"
"strings"
)

// The scripts that act on a running VM ship with the CLI rather than in the
// image. Both carry a value the image cannot know -- a token generated per
// install, and whatever port the host had free -- and both have to be fixable
// without rebuilding an image and recreating every VM booted from one.
//
//go:embed scripts/set-bootstrap-token.sh
var bootstrapTokenScript string

//go:embed scripts/set-ingress-port.sh
var ingressPortScript string

const (
// BootstrapTokenPrefix marks a token this CLI minted for a local VM, so a
// credential stored under the same profile by something else — a remote
Expand All @@ -18,19 +30,15 @@ const (
// what the rest of the platform uses for service tokens.
bootstrapTokenBytes = 32

// bootstrapTokenScript ships in the image. It installs a host-supplied
// token into the Gateway's environment and restarts the deployment, and is
// idempotent: handing it the token already in place changes nothing.
bootstrapTokenScript = "/opt/agyn/set-bootstrap-token.sh"

// ingressPortScript ships in the image. It points the browser-facing URLs
// (the OIDC redirects, the media proxy origin, its CORS allowlist) at the
// port this host forwards, and like the token script is idempotent.
ingressPortScript = "/opt/agyn/set-ingress-port.sh"

// platformNamespace holds the platform workloads inside the VM.
platformNamespace = "agyn-platform"

// dexConfigMap holds the shipped provider's config. Named for the chart's
// resource, not the release: reading "dex" found nothing, and nothing is
// how this reports "not the shipped provider" -- so the credentials simply
// never printed.
dexConfigMap = "dex-config"

// systemOrganization is the declaration the release ships for the
// organization platform-provisioned resources live in. Its status carries
// the id the platform assigned, which is the organization every org-scoped
Expand Down Expand Up @@ -62,12 +70,13 @@ func IsBootstrapToken(token string) bool {
// SetBootstrapToken installs the token this host holds into the running VM and
// returns the script's log output. The value travels over the limactl channel,
// never the network, and is never read back: the host keeps the copy it
// generated.
func SetBootstrapToken(token string) (string, error) {
// generated. It is handed over on stdin rather than as an argument, so it is in
// neither machine's process list.
func SetBootstrapToken(token string, onDetail func(string)) (string, error) {
if strings.TrimSpace(token) == "" {
return "", fmt.Errorf("bootstrap token must not be empty")
}
out, err := Shell("sudo", bootstrapTokenScript, token)
out, err := RunScriptWithSecret(bootstrapTokenScript, strings.NewReader(token), onDetail)
if err != nil {
return "", fmt.Errorf("install the bootstrap token in the VM: %w", err)
}
Expand All @@ -81,13 +90,13 @@ func SetBootstrapToken(token string) (string, error) {
// already be taken. Only browser-facing URLs are affected — everything inside
// the cluster, the OpenZiti advertised addresses included, uses an internal
// port that never changes.
func SetIngressPort(port int) (string, error) {
func SetIngressPort(port int, onDetail func(string)) (string, error) {
if port <= 0 || port > 65535 {
return "", fmt.Errorf("ingress port %d is out of range", port)
}
out, err := Shell("sudo", ingressPortScript, strconv.Itoa(port))
out, err := RunScriptProgress(ingressPortScript, onDetail, strconv.Itoa(port))
if err != nil {
return "", fmt.Errorf("set the ingress port in the VM: %w", err)
return "", fmt.Errorf("point the platform's URLs at port %d: %w", port, err)
}
return strings.TrimSpace(out), nil
}
Expand All @@ -109,3 +118,46 @@ func OrganizationID() (string, error) {
}
return id, nil
}

// Account is a sign-in the bundled provider ships with.
type Account struct {
Label string
Username string
Password string
}

// bundledAccounts are the static logins the dex subchart ships. The passwords
// are bcrypt hashes in the chart, so the plaintext cannot be read back from a
// running VM -- it is a property of the shipped config, and printing it is only
// right while that config is the one in place.
//
// Named by address, which is the only thing Dex authenticates a static user by.
// Printing the local part instead is what sends someone into an account stored
// under "admin", against which the cluster-admin declaration for
// admin@<domain> has nothing to resolve -- a sign-in that works and a role that
// never arrives.
var bundledAccounts = []Account{
{Label: "Regular user (recommended)", Username: "user@" + BaseDomain, Password: "user"},
{Label: "Cluster admin", Username: "admin@" + BaseDomain, Password: "admin"},
}

// BundledAccounts returns the sign-ins to print, or nothing.
//
// Nothing unless the VM runs the shipped Dex config: Keycloak's accounts are
// different, an install pointed at its own issuer has none of ours, and a VM
// whose dex.users were replaced would be handed credentials that do not work.
// Each of those is worse than printing no credentials at all, so the check is
// for the two accounts this CLI knows the passwords of.
func BundledAccounts() []Account {
config, err := Shell("sudo", "kubectl", "-n", platformNamespace,
"get", "configmap", dexConfigMap, "-o", `jsonpath={.data.config\.yaml}`)
if err != nil {
return nil
}
for _, account := range bundledAccounts {
if !strings.Contains(config, account.Username) {
return nil
}
}
return bundledAccounts
}
6 changes: 3 additions & 3 deletions internal/local/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ func TestIsBootstrapTokenRecognisesOnlyItsOwn(t *testing.T) {
}

func TestSetBootstrapTokenRejectsAnEmptyValue(t *testing.T) {
// Empty is what the in-VM script reads as "leave the image placeholder in
// place" — silently provisioning nothing while reporting success.
if _, err := SetBootstrapToken(" "); err == nil {
// The script refuses an empty read too, but this check is what keeps the
// VM from being reached at all for a value that cannot be right.
if _, err := SetBootstrapToken(" ", nil); err == nil {
t.Fatal("expected an empty token to be rejected before touching the VM")
}
}
Expand Down
Loading
Loading