Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 22 additions & 22 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1320,25 +1320,25 @@ jobs:
# 7) Stop AWS EC2 runner instances
# ---------------------------------------------------------------------------

post-run:
name: Stop AWS EC2 runners
needs: [pre-run, prepare, build-amd, build-arm, build-armv7, create-manifest, sign-and-release]
if: ${{ always() && needs.pre-run.result == 'success' }}
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Configure AWS credentials (OIDC)
uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_ROLE_NAME }}
role-duration-seconds: 3600
aws-region: ${{ secrets.AWS_REGION }}

- name: Verify AWS identity
run: aws sts get-caller-identity

- name: Stop EC2 instances
run: |
aws ec2 stop-instances --instance-ids ${{ secrets.EC2_INSTANCE_ID_AMD_RUNNER }}
aws ec2 stop-instances --instance-ids ${{ secrets.EC2_INSTANCE_ID_ARM_RUNNER }}
echo "EC2 instances stopped"
# post-run:
# name: Stop AWS EC2 runners
# needs: [pre-run, prepare, build-amd, build-arm, build-armv7, create-manifest, sign-and-release]
# if: ${{ always() && needs.pre-run.result == 'success' }}
# runs-on: ubuntu-latest
# permissions: write-all
# steps:
# - name: Configure AWS credentials (OIDC)
# uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
# with:
# role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_ROLE_NAME }}
# role-duration-seconds: 3600
# aws-region: ${{ secrets.AWS_REGION }}

# - name: Verify AWS identity
# run: aws sts get-caller-identity

# - name: Stop EC2 instances
# run: |
# aws ec2 stop-instances --instance-ids ${{ secrets.EC2_INSTANCE_ID_AMD_RUNNER }}
# aws ec2 stop-instances --instance-ids ${{ secrets.EC2_INSTANCE_ID_ARM_RUNNER }}
# echo "EC2 instances stopped"
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ RUN apk --no-cache add ca-certificates tzdata iputils
COPY --from=builder /pangolin-cli /usr/local/bin/
COPY entrypoint.sh /

# Marks this as an official Fossorial container image.
# Auto-update is disabled in official images, update by pulling a new image tag.
ENV NEWT_SYSTEM_SUBSTRATE="CONTAINER"

# Admin/metrics endpoint (Prometheus scrape)
EXPOSE 2112

Expand Down
18 changes: 10 additions & 8 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Security Policy

If you discover a security vulnerability, please follow the steps below to responsibly disclose it to us:
If you discover a security vulnerability, please report it privately using GitHub Security Advisories. Do not create a public GitHub issue or discussion post, as this could put the security of other users at risk.

1. **Do not create a public GitHub issue or discussion post.** This could put the security of other users at risk.
2. Send a detailed report to [security@pangolin.net](mailto:security@pangolin.net) or send a **private** message to a maintainer on [Discord](https://discord.gg/HCJR8Xhme4). Include:
## How to report

- Description and location of the vulnerability.
- Potential impact of the vulnerability.
- Steps to reproduce the vulnerability.
- Potential solutions to fix the vulnerability.
- Your name/handle and a link for recognition (optional).
1. Go to the [Security Advisories page](https://github.com/fosrl/cli/security/advisories/new) for this repository, or open the "Security" tab and select "Report a vulnerability".
2. Describe the vulnerability and include:

- Description and location of the vulnerability.
- Potential impact of the vulnerability.
- Steps to reproduce the vulnerability.
- Potential solutions to fix the vulnerability.
- Your name/handle and a link for recognition (optional).

We aim to address the issue as soon as possible.
13 changes: 11 additions & 2 deletions cmd/auth/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/fosrl/cli/internal/config"
"github.com/fosrl/cli/internal/logger"
"github.com/fosrl/cli/internal/utils"
"github.com/muesli/cancelreader"
"github.com/pkg/browser"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -117,9 +118,17 @@ func loginWithWeb(hostname string, sessionCookieName string, knownEmail string)
logger.Info("First copy your one-time code: %s", code)
logger.Info("Press Enter to open %s in your browser...", baseLoginURL)

// Wait for Enter in a goroutine (non-blocking) and open browser when pressed
// The stdin reader must be cancelled before returning, otherwise it keeps
// consuming keystrokes meant for later interactive prompts.
stdinReader, err := cancelreader.NewReader(os.Stdin)
if err != nil {
return "", fmt.Errorf("failed to read from stdin: %w", err)
}
defer stdinReader.Close()
defer stdinReader.Cancel()

go func() {
reader := bufio.NewReader(os.Stdin)
reader := bufio.NewReader(stdinReader)
_, err := reader.ReadString('\n')
if err == nil {
// User pressed Enter, open browser
Expand Down
41 changes: 41 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,32 @@ func commandExemptFromCompanionReady(cmd *cobra.Command) bool {
return true
}

// A machine client (`up client` with its own id/secret) never uses the
// desktop app's account, so it must not wait for the desktop app to be
// ready. This matters under a service, which runs as SYSTEM/root where
// the desktop app is never logged in.
if cmd.Name() == "client" && commandHasAncestor(cmd, "up") && hasMachineClientCredentials(cmd) {
return true
}

return false
}

// hasMachineClientCredentials reports whether `up client` was given machine
// client credentials, by flag or by the environment variables its PreRunE
// falls back to (which the service sets).
func hasMachineClientCredentials(cmd *cobra.Command) bool {
id := os.Getenv("PANGOLIN_CLIENT_ID")
secret := os.Getenv("PANGOLIN_CLIENT_SECRET")
if f := cmd.Flags().Lookup("id"); f != nil && f.Changed {
id = f.Value.String()
}
if f := cmd.Flags().Lookup("secret"); f != nil && f.Changed {
secret = f.Value.String()
}
return id != "" && secret != ""
}

func commandHasAncestor(cmd *cobra.Command, name string) bool {
for p := cmd.Parent(); p != nil; p = p.Parent() {
if p.Name() == name {
Expand Down Expand Up @@ -276,6 +299,24 @@ func ensureRuntimeDirs(cfg *config.Config) {
}

// Execute is called by main.go
// ExecuteArgs runs the CLI with args instead of os.Args, stopping it when
// ctx is cancelled.
func ExecuteArgs(ctx context.Context, args []string) error {
cmd, err := RootCommand(true)
if err != nil {
return err
}
// Keep the context RootCommand set up (it carries the config) and only
// add ctx's cancellation to it.
runCtx, cancel := context.WithCancel(cmd.Context())
defer cancel()
stopAfter := context.AfterFunc(ctx, cancel)
defer stopAfter()

cmd.SetArgs(args)
return cmd.ExecuteContext(runCtx)
}

func Execute() {
cmd, err := RootCommand(true)
if err != nil {
Expand Down
18 changes: 7 additions & 11 deletions cmd/service/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ func clientInstallCmd() *cobra.Command {
immediately.

Intended for machine clients (--id/--secret), which don't have an
interactively logged-in user to restart them. On Windows this only supports
the service itself - 'pangolin up client' has no standalone Windows console
mode (that's handled by the Pangolin desktop app); the service runs the
tunnel directly in-process instead.`,
interactively logged-in user to restart them. The service runs
'pangolin up client --attach' on every platform (on Windows inside the
service process itself).`,
Run: func(cmd *cobra.Command, args []string) {
envVars := map[string]string{
"PANGOLIN_CLIENT_ID": opts.ID,
Expand All @@ -52,13 +51,10 @@ tunnel directly in-process instead.`,
Name: clientServiceName,
DisplayName: "Pangolin Client",
Description: "Runs 'pangolin up client' persistently in the background",
// On Linux/macOS, Args is the subprocess command line
// (--attach runs in the foreground under the service
// supervisor's control, no self-detaching subprocess/TUI).
// Windows ignores Args for the client service and instead
// runs the tunnel in-process (see svcmgr_windows.go) - it's
// kept here for documentation/parity. Credentials always
// come from the environment rather than the command line so
// Args is the command the service supervisor runs
// (--attach runs in the foreground under its control, no
// self-detaching subprocess/TUI). Credentials always come
// from the environment rather than the command line so
// they don't leak into `ps`/Task Manager.
Args: []string{"up", "client", "--attach"},
EnvVars: envVars,
Expand Down
Loading