Skip to content

Latest commit

 

History

History
231 lines (154 loc) · 3.67 KB

File metadata and controls

231 lines (154 loc) · 3.67 KB

Setting Up the Foundation: The Git Setup

Configuring the Git Repository

cd $HOME/RestQR
git init
# Ignore Python unnecessary files
curl https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore \
    > $HOME/RestQR/.gitignore

# Ignore Terraform unnecessary files
curl https://raw.githubusercontent.com/github/gitignore/refs/heads/main/Terraform.gitignore \
    >> $HOME/RestQR/.gitignore
git checkout -b main
git config --global user.email "admin@restqr.app"
git config --global user.name "RestQR"
cat <<EOF >>~/.bashrc && source ~/.bashrc
export GITLAB_API_TOKEN="<CHANGE_ME>"
EOF
# Add WakeMeOps repository
curl -sSL \
    "https://raw.githubusercontent.com/upciti/wakemeops/main/assets/install_repository" | \
    bash

# Install glab
apt install glab -y
glab auth login \
    --hostname gitlab.com \
    --token $GITLAB_API_TOKEN
glab auth status
ssh-keygen -t rsa -b 4096 \
    -C "admin@restqr.app" \
    -f ~/.ssh/id_rsa -N ""
glab ssh-key add \
    ~/.ssh/id_rsa.pub \
    -t "RestQR"
# Change the values based on your preferences and available names
cat <<EOF >>~/.bashrc && source ~/.bashrc
export GITLAB_INSTANCE=gitlab.com
export GITLAB_GROUP=RestQR
export GITLAB_PROJECT=RestQR
EOF
# Cd into the RestQR folder
cd $HOME/RestQR

# Create a new GitLab repository
glab repo create \
    --name $GITLAB_PROJECT \
    --group $GITLAB_GROUP \
    --description "RestQR application" \
    --private
git remote -v
git add .
git commit -m "Initial commit"
git push origin main
echo "https://$GITLAB_INSTANCE/$GITLAB_GROUP/$GITLAB_PROJECT"

General Git Security Considerations

Access Control and Unauthorized Access

Branch Protection

Tags and Releases

Unsigned Commits and Commit Signing

git config --global user.email "sofia@restqr.com
git config --global user.name "Sofia"
git commit -m "This is a commit from Sofia"
gpg --list-secret-keys
export REAL_NAME="<YOUR_REAL_NAME>"
export EMAIL="<YOUR_EMAIL>"
gpg --full-gen-key --batch <( \
    echo "Key-Type: 1"; \
    echo "Key-Length: 4096"; \
    echo "Subkey-Type: 1"; \
    echo "Subkey-Length: 4096"; \
    echo "Expire-Date: 0"; \
    echo "Name-Real: $REAL_NAME"; \
    echo "Name-Email: $EMAIL"; \
    echo "%no-protection"; )
gpg --list-secret-keys --keyid-format LONG $EMAIL
sec   rsa4096/4AB65574279303ED 2025-03-21 [SCEAR]
      BE9988E5C86F392320406F944AB65574279303ED
uid                 [ultimate] Sofia <sofia@restqr.com>
ssb   rsa4096/7D3D8C7A2FD81B94 2025-03-21 [SEA]
export KEY_ID="<KEY_ID>"
gpg --armor --export $KEY_ID
# Sign all commits by default in all repositories
git config --global user.signingkey $KEY_ID
git config --global commit.gpgsign true
# Create a new file and add some content
echo $(date) > test.txt

# Add the file to the staging area
git add test.txt

# If you've already configured git to always sign commits with:
# git config --global commit.gpgsign true
# git config --global user.signingkey <KEY_ID>
# Then you can omit the `-S` option:
git commit -m "Test commit" -S

# Verify the commit signature
git log --show-signature

# Push the commit to the remote repository
git push origin main

Git commit signature verification

Passwordless Authentication

git remote -v
# Already done by the glab command
git remote set-url \
    origin git@$GITLAB_INSTANCE:$GITLAB_GROUP/$GITLAB_PROJECT.git