mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
* Connect to remote SSH nodes using SSH CLI Replace Go-native SSH implementation with SSH CLI execution to support diverse SSH configurations and agents. Implements 'uncloudd dial-stdio' subcommand that proxies gRPC connections over stdin/stdout, similar to Docker's approach. This change addresses compatibility issues with: - SSH agents exposing many keys (1Password, causing "too many authentication failures") - Tailscale SSH (which doesn't support advanced SSH channel types like direct-streamlocal) - Custom SSH configurations in ~/.ssh/config The dial-stdio approach reduces SSH feature requirements by streaming the unix socket connection over stdin/stdout instead of using SSH channel forwarding. Changes: - Add 'uncloudd dial-stdio' hidden subcommand for socket proxy - Add SSHCLIConnector using ssh command + dial-stdio - Update connection logic to use SSH CLI connector - Maintain backward compatibility with SSHKeyFile config Resolves #131 * Fix sshcli tests missing ConnectionTimeout Introduced short connection timeout on the first change but forgot to update tests to match. * Add SSHCLI field and update MachineConnection String() format - Add SSHCLI field to support ssh_cli YAML configuration - Update String() to use URI-like format (ssh://, ssh+cli://, tcp://) * Add Validate() method and tests for MachineConnection - Add Validate() to ensure connection methods are mutually exclusive - Add tests for validation and String() method * Unify SSH connector configs to use SSHConnectorConfig * Update connectCluster to support both SSH connector types * Restore Go SSH connector as default for machine init/add Revert provisionOrConnectRemoteMachine to use Go SSH connector: - Root users: reuse SSH connection from provisioning - Non-root users: establish new connection for group membership - Remove SSH CLI as default connector SSH CLI connector remains available via ssh_cli config field. * Add sshCLIDialer with DialContext method Implement proxy.ContextDialer for SSHCLIConnector using SSH -W flag. Each dial spawns a new SSH process for TCP forwarding, enabling independent connections separate from the gRPC dial-stdio connection. * Implement SSHCLIConnector.Dialer() method Return sshCLIDialer instead of error, enabling uc image push functionality with SSHCLIConnector. Validates connector is configured before returning dialer. * Fix half-closing implementation matchin Docker's approach * Use testify assertions for connection tests * Allow ssh+cli:// to be used with --connect This way I can skip the configuration file while testing things out, and confirm it works correctly: $ unset SSH_AUTH_SOCK $ ./uncloud --connect ssh://provision@blatta11 machine ls Error: connect to cluster: connect to machine: SSH login to provision@blatta11:22: connect using SSH agent: connect to SSH agent: dial unix: missing address $ ./uncloud --connect ssh+cli://provision@blatta11 machine ls NAME STATE ADDRESS PUBLIC IP WIREGUARD ENDPOINTS MACHINE ID blatta11 Up 10.210.0.1/24 - 100.64.0.22:51820, ... * Validates configuration before connecting to cluster * Do not tie client constructor with real validation No longer attempt to validate the connection when instantiating a new client. Later on we could validate it in different places. * Cleanup test and remove AI-slop There were some serious slop in those tests, so took the time to clean them up and kept only the relevant ones. There is some repetition between buildSSHArgs and buildDialArgs but can be tackled at a later stage. * Fix connection representation tests Prefix connection with ssh ssh+cli respectively. * Wait for stdout before returning Missed copy & pasta from Docker dial-stdio implementation (this happens when you stare at the code for too long that it burns your eyes).
61 lines
2.1 KiB
Docker
61 lines
2.1 KiB
Docker
ARG ALPINE_VERSION=3.20.3
|
|
|
|
FROM golang:1.25.1-alpine AS uncloudd
|
|
|
|
ARG TARGETOS
|
|
ARG TARGETARCH
|
|
|
|
ENV CGO_ENABLED=0
|
|
|
|
WORKDIR /build
|
|
# Download and cache dependencies and only redownload them in subsequent builds if they change.
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download && go mod verify
|
|
|
|
COPY . .
|
|
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o uncloudd ./cmd/uncloudd
|
|
|
|
|
|
FROM alpine:${ALPINE_VERSION} AS corrosion-download
|
|
ARG TARGETARCH
|
|
|
|
RUN CORROSION_ARCH=$(case "${TARGETARCH}" in \
|
|
"amd64") echo "x86_64" ;; \
|
|
"arm64") echo "aarch64" ;; \
|
|
*) echo "Architecture '${TARGETARCH}' not supported" >&2 && exit 1 ;; \
|
|
esac) \
|
|
&& wget -q -O /tmp/corrosion.tar.gz \
|
|
"https://github.com/psviderski/corrosion/releases/latest/download/corrosion-${CORROSION_ARCH}-unknown-linux-gnu.tar.gz" \
|
|
&& tar -xzf /tmp/corrosion.tar.gz -C /tmp \
|
|
&& install /tmp/corrosion /usr/local/bin/corrosion \
|
|
&& rm /tmp/corrosion.tar.gz /tmp/corrosion
|
|
|
|
# Beware that more modern images like chainguard/wolfi-base build glibc with flags that require newer CPU features,
|
|
# e.g. x86-64-v2. So such image may fail with "Fatal glibc error: CPU does not support x86-64-v2" on older CPUs.
|
|
FROM gcr.io/distroless/cc-debian12:latest AS corrosion
|
|
COPY --from=corrosion-download /usr/local/bin/corrosion /usr/local/bin/corrosion
|
|
CMD ["corrosion", "agent"]
|
|
|
|
|
|
FROM alpine:${ALPINE_VERSION} AS corrosion-image-tarball
|
|
ARG CORROSION_IMAGE="ghcr.io/psviderski/corrosion:latest"
|
|
|
|
RUN apk --no-cache add crane
|
|
RUN crane pull "${CORROSION_IMAGE}" /corrosion.tar
|
|
|
|
|
|
# Uncloud-in-Docker (ucind) image for running Uncloud test clusters using Docker.
|
|
FROM docker:27.3.1-dind AS ucind
|
|
# Create system group and user 'uncloud'.
|
|
RUN addgroup -S uncloud && adduser -SHD -h /nonexistent -G uncloud -g "" uncloud
|
|
RUN apk --no-cache add \
|
|
socat \
|
|
wireguard-tools
|
|
|
|
COPY --from=corrosion-image-tarball /corrosion.tar /images/corrosion.tar
|
|
COPY scripts/docker/dind scripts/docker/entrypoint.sh /usr/local/bin/
|
|
COPY --from=uncloudd /build/uncloudd /usr/local/bin/
|
|
|
|
ENTRYPOINT ["entrypoint.sh"]
|
|
CMD ["uncloudd"]
|