[go: up one dir, main page]

Skip to content

GIT environment variables are not available when connecting to a workspace via SSH

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

GIT environment variables are not available when connecting to a workspace via SSH

Steps to reproduce

  • Configure Workspaces to work with SSH according to Connect to a workspace with SSH and try connect to your workspace.
  • When connecting via UI, run env | grep GIT and observe that git-related environment variables are available:
gitlab-workspaces@workspace-11-1-rkppia-847d69d549-rd64x:/projects/workspace-project$ env | grep GIT
GL_GIT_CREDENTIAL_STORE_FILE_PATH=/.workspace-data/variables/file/gl_git_credential_store.sh
GITLAB_WORKFLOW_INSTANCE_URL=https://GITLAB_URL/
GIT_CONFIG_VALUE_2=admin@example.com
GIT_CONFIG_VALUE_1=Administrator
GIT_CONFIG_VALUE_0=/.workspace-data/variables/file/gl_git_credential_store.sh
GITLAB_WORKFLOW_TOKEN_FILE=/.workspace-data/variables/file/gl_token
GIT_CONFIG_COUNT=3
GIT_CONFIG_KEY_1=user.name
GIT_CONFIG_KEY_0=credential.helper
GIT_CONFIG_KEY_2=user.email
  • Connect to the same workspace via SSH and run env | grep GIT too.

What is the current bug behavior?

GIT variables are not set:

gitlab-workspaces@workspace-11-1-rkppia-847d69d549-rd64x:/projects/workspace-project$ env | grep GIT
gitlab-workspaces@workspace-11-1-rkppia-847d69d549-rd64x:/projects/workspace-project$

What is the expected correct behavior?

According to the internal discussion with @vtak, it is not expected, and variables should be set.

Additional information

The image I've specified in the .devfile.yaml uses this Dockerfile:

FROM ubuntu:20.04

# Install `openssh-server` and other dependencies
# Note, need to install recent git releases when using ubuntu 20.04 image
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y && apt-get install -y openssh-server sudo curl git wget software-properties-common apt-transport-https locales tmux screen \
    bash-completion gdb-multiarch libjson-perl ruby unifdef libarchive-extract-perl \
    && apt-add-repository ppa:git-core/ppa \
    && apt-get update \
    && apt-get install -y git \
    && rm -rf /var/lib/apt/lists/

# Permit empty passwords
RUN sed -i 's/nullok_secure/nullok/' /etc/pam.d/common-auth
RUN echo "PermitEmptyPasswords yes" >> /etc/ssh/sshd_config

# Generate a workspace host key
RUN ssh-keygen -A
RUN chmod 775 /etc/ssh/ssh_host_rsa_key && \
    chmod 775 /etc/ssh/ssh_host_ecdsa_key && \
    chmod 775 /etc/ssh/ssh_host_ed25519_key

# Create a `gitlab-workspaces` user
RUN useradd -l -u 5001 -G sudo -md /home/gitlab-workspaces -s /bin/bash gitlab-workspaces
RUN passwd -d gitlab-workspaces
ENV HOME=/home/gitlab-workspaces
WORKDIR $HOME
RUN mkdir -p /home/gitlab-workspaces && chgrp -R 0 /home && chmod -R g=u /etc/passwd /etc/group /home

# Allow sign-in access to `/etc/shadow`
RUN chmod 775 /etc/shadow

RUN wget -O /usr/local/bin/kubectl https://dl.k8s.io/release/v1.29.4/bin/linux/amd64/kubectl && chmod 755 /usr/local/bin/kubectl

RUN locale-gen en_US.UTF-8

USER gitlab-workspaces
  • It is not possible to make a commit because username and email are not set. After setting git config --global user.email and git config --global user.name, I was able to make a commit to the repo.
Edited by 🤖 GitLab Bot 🤖