gitlab 설치 및 설정
- 1 gitlab 전체 기능 확인
- 1.1 버전관리
- 1.2 프로젝트 관리
- 1.3 gitlab 서비스 운영, 보안
- 1.4 사용자
- 1.5 CICD
- 1.6 부가기능, 기타
- 1.7 실제 사용을 한다면 추가로 확인을 해야 할 부분
- 2 gitlab install
- 2.1 docker install
- 2.2 VM install
- 2.3 설치 권장사항
- 3 VCS 구성
- 4 User 할것
- 5 admin
- 5.1 admin 확인해야 할 것
- 5.2 ssl 설정
- 5.3 smtp
- 5.4 backup and restore
- 5.5 관리작업
- 5.5.1 서비스 상태 체크, 로그보기
- 5.5.2 접근제어
- 6 CICD
- 6.1 CICD 주요 기능 요약
- 6.2 CICD 파이프라인 구성
- 6.3 CICD 추가기능
- 6.4 gitlab vs github
- 6.5 gitlab runner 설치 및 등록
- 6.6 gitlab runner 윈도우 서버
- 7 다른 툴과 연동
- 7.1 docker registry
2021년 테스팅을 했던 자료
gitlab 전체 기능 확인
SCM
버전관리, 코드 리뷰, 승인 과정(PR)
프로젝트 관리 기능 : 이슈트래킹, wiki
CICD
기능 - 개발 및 커밋 - 빌드 및 단위 테스트 - 통합 - 빌드 - 통합 테스트 - 패키징
바이너리 관리 (아티팩트) : 각종 애플리케이션, docker
지속적 배포/배포자동화
API 연동
표준 CICD 파이프라인 수립 : 애플리케이션, 인프라 (클라우드 리소스 프로비저닝, OS 설정관리 등)
운영, 보안상의 요구사항
group, project, user 관리.
백업, 보안, 장애시 처리
버전관리
버전관리, 코드리뷰, 승인(PR)
project, user, group 관리.
역할구분 : Guest, Reporter, Developer, Maintainer, Owner로 역할. Master 브랜치, Protected 브랜치에는 Push 할 수 없으므로 해당 프로젝트 관리자에게 Maintainer, Owner 역할 주면 될 듯.
API : API 확인.
MR : merge request approval 기능은 있는데 Free 버전에는 강제로 승인과정을 넣을 수 없다. 이 부분은 역할구분을 통해서 처리할 수는 있다.
프로젝트 관리
이슈 : 간단히 사용만 해봄.
위키 : 아주 간단한 기능만 제공.
gitlab 서비스 운영, 보안
설치하기 : Reference architectures, 설치 권장사항 확인. docker 설치, deb 패키지로 설치
설정 : timezone, smtp 설정, backup 및 복원하기
관리 : 서비스관리, 로그 보기
보안 : SSL, 2FA
사용자
사용자 설정(시간, 2FA, 언어, 이메일 알림), ssh key 등록, git 사용.
CICD
부가기능, 기타
docker registry 제공
terraform remote state 제공 (terraform을 여러 명이 협업해서 사용을 할 경우 필요한 기능인데 locking 기능은 제공을 안 할 듯 함)
실제 사용을 한다면 추가로 확인을 해야 할 부분
장애시 처리
보안부분
프로그램 업데이트
시스템 모니터링, 메트릭 수집.
gitlab install
13.11.2-ee
docker install
https://docs.gitlab.com/omnibus/docker/
DOCKER 로 설치.
VM install
sudo apt-get update
sudo apt-get install -y curl openssh-server ca-certificates tzdata perl
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash
EXTERNAL_URL="http://gitlab.example.com" apt-get install gitlab-ee=13.11.2-ee.0
설치 권장사항
https://docs.gitlab.com/ee/administration/reference_architectures/1k_users.html
천명이하일 경우 가용성 요구사항이 없으면 단일노드에 설치하고 자동백업을 설정해서 사용함.
최대 500 4 개의 vCPU, 3.6GB 메모리
https://docs.gitlab.com/ee/install/requirements.html#hardware-requirements
CPU 최소 4코어. RAM 4G
VCS 구성
groups - 그룹에 user 추가하여 관리하거나 다른 groups를 추가할 수 있음. 하위에 project 생성.
user 추가. (tjmoon) group에 추가
https://insight.infograb.net/docs/user/members_permissions
GitLab에서는 Guest, Reporter, Developer, Maintainer, Owner로 역할을 구분하여 접근 권한을 부여.
Owner : 프로젝트 및 제품을 관리
Maintainer : Master에 Push 하고 Production으로 배포
Developer : Master 브랜치, Protected 브랜치에는 Push 할 수 없습니다. Feature 브랜치에 Push 후 워크플로우에 따라 Merge Request를 작성하여 승인을 요청
User 할것
gitlab 설정
Profile - Time zone : seoul
Account - Two-Factor Authentication : 2FA OTP 설정
Preferences - Localization - 한국어
이메일 통지 조정 : global, project, group 별 설정 가능함. https://docs.gitlab.com/ee/user/profile/notifications.html
gitlab 사용
ssh key 생성하여 등록하기. gitlab 과의 연동 확인.
https://docs.gitlab.com/ee/ssh/README.html 문서 참고.
ssh-keygen -t ed25519 -C "test"
# ~/.ssh/ 밑에 id_ed25519, id_ed25519.pub 생성.
cat ~/.ssh/config
Host gitlab.example.com
IdentityFile ~/.ssh/id_ed25519
Port 2222
# git ssh test
ssh -T git@gitlab.example.com
https://insight.infograb.net/docs/user/ssh_keys
윈도우 사용자용도 내용 필요함.
git 설치
git 설정
https://insight.infograb.net/docs/user/git_config_auth/
git config --global user.name "tjmoon"
git config --global user.email "tjmoon@gitlab.example.com"
admin
admin 확인해야 할 것
특정 user와 project 권한 설정하기 : project 에서 user 권한 변경했는데. groups 관리에서 Manage access에서 변경함.
timezone 설정 : UTC +9
Sign-up enabled : 기본 활성화되어 있음. 실서비스를 할 경우에는 비활성화?
2FA 인증은 실서비스시 활성화 필요.
user 추가시 group 생성 권한도 가지고 있음. 없애는 것이 좋겠음.
ssl 설정
self-sign 인증서 만들기
openssl req -newkey rsa:4096 \
-x509 \
-sha256 \
-days 3650 \
-nodes \
-out example.crt \
-keyout example.key \
-subj "/C=KR/ST=mapo/L=Seoul/O=Security/OU=IT Department/CN=gitlab.example.com"
SSL 인증서를 설정해서 사용하면 인증서 설치하고 external_url 설정을 해야 함. 그 이후에는 https로만 접속 가능. http로 오는 것을 https로 redirect 할 수는 있음.
https://docs.gitlab.com/omnibus/settings/nginx.html#manually-configuring-https
external_url "https://gitlab.example.com"
smtp
https://docs.gitlab.com/omnibus/settings/smtp.html#testing-the-smtp-configuration
기본은 sendmail을 써서 메일을 보내는 것으로 하는 것 같은데 로컬에 smtp가 있다면 그걸 사용하는것이 기본인 듯하다.
postfix를 기본 옵션 internet 으로 해서 설치했다. 위의 smtp 설정 문서를 보면 smtp 디버깅하는 방법이 있다.
https://docs.gitlab.com/ee/administration/reply_by_email_postfix_setup.html
backup and restore
https://docs.gitlab.com/ee/raketasks/backup_restore.html
backup 하기 : 백업명령 실행하여 데이타에 대한 백업파일 만들고 설정파일이 있는 디렉토리를 백업 함.
docker exec -t <container name> gitlab-backup create
backup 명령을 실행하면 /var/opt/gitlab/backups/ 디렉토리에 tar 파일로 백업을 해준다. /etc/gitlab/gitlab-secrets.json, /etc/gitlab/gitlab.rb files 은 sensitive data 가 들어있어서 백업하지 않으므로 수동으로 백업을 해야 한다. 초기 설치시 gitlab.rb 에는 아무런 설정이 들어 있지 않았다. docker 로 설치한 경우 설정파일 디렉토리 /srv/gitlab/config 를 백업하라고 나와 있다.
백업 을 생성 한 GitLab 의 정확히 동일한 버전 및 유형 (CE / EE) (예 : CE 9.1.0)으로 만 백업을 복원 할 수 있습니다 .
docker 설치시 restore 하기.
gitlab-ctl stop unicorn
gitlab-ctl stop puma
gitlab-ctl stop sidekiq
gitlab-ctl status
gitlab-backup restore BACKUP=11493107454_2018_04_25_10.6.4-ce
gitlab.rb and gitlab-secrets.json 복구. /etc/gitlab 디렉토리
# Restart the GitLab container
#docker restart <name of container>
gitlab-rake gitlab:check SANITIZE=true
패키지 설치시 복구하기
docker 로 복구하는 경우와 거의 비슷하지만 몇가지 해주어야 하는 작업이 있음. 아래 문서 참고.
https://docs.gitlab.com/ee/raketasks/backup_restore.html#restore-for-omnibus-gitlab-installations
관리작업
서비스 상태 체크, 로그보기
https://docs.gitlab.com/omnibus/maintenance/README.html#get-service-status
https://docs.gitlab.com/omnibus/settings/logs.html
접근제어
IP 주소로 그룹 액세스 제한 (premium 부터 지원)
https://docs.gitlab.com/ee/user/group/#restrict-group-access-by-ip-address
CICD
CICD 주요 기능 요약
파이프라인 구성 : 간단한 파이프라인 구성. 배포는 ssh 이용한 것만 테스팅을 해 보았음. environments 이용하여 배포 기록 남기고 과거 버전으로 롤백 할 수 있음.
variable 설정. secret 설정도 가능함.
패키지기능 : generac package 로 작동 확인
Runner : 설치 및 등록. OS는 Ubuntu 20.04 이용. 특정 runner 및 공유 runner. executor 로 docker, shell 로 실행하는 것 테스팅. 윈도우즈 runner 테스팅했음.
배포 : k8s와 연동 기능 있음.
environments, Review Apps 를 이용하여 피처 브랜치에서 변경이 있는 경우 바로 확인 가능.
CICD 파이프라인 구성
규모가 커짐에 따라서 어떻게 gitlab에서 cd 배포 하는지 참고가 되는 글. environments, review apps 이용한 예제임.
https://about.gitlab.com/blog/2021/02/05/ci-deployment-and-environments/
gitlab CICD 기본문서
https://docs.gitlab.com/ee/ci/README.html
CICD template https://gitlab.com/gitlab-org/gitlab/-/tree/master/lib/gitlab/ci/templates
CICD 예제 : 브라우저 성능 테스트, 배포, End to End 테스트, 부하 성능 테스트
https://docs.gitlab.com/ee/ci/examples/
예제프로젝트 https://gitlab.com/gitlab-examples?page=1
gitlab CICD quick start : https://docs.gitlab.com/ee/ci/quick_start/
https://docs.gitlab.com/ee/ci/yaml/#stage
stage 는 정의를 하지 않으면 기본으로 5가지가 사용된다. .pre, build,test, deploy, .post
ssh 이용하는 경우 다음 내용 참고.
https://docs.gitlab.com/ee/ci/examples/deployment/composer-npm-deploy.html
environments 이용하여 배포 기록 남기고 과거 버전으로 롤백 할 수 있음.
https://docs.gitlab.com/ee/ci/environments/
review apps를 이용하면 개별 피쳐 브랜치마다 테스팅을 자동으로 하도록 구성할 수 있음.
https://docs.gitlab.com/ee/ci/review_apps/
CICD 추가기능
테스팅과 관련한 각종 툴이 통합 : 단위 테스트 보고서, 접근성 테스트, 브라우저 성능 테스트, 코드 품질, 부하 성능 테스트, 메트릭 레포트, (https://docs.gitlab.com/ee/ci/unit_test_reports.html )
보안 관련한 많은 기능이 있지만 ultimate에서 지원함. (https://docs.gitlab.com/ee/user/application_security/index.html )
Auto DevOps : 유용할 수는 있지만 사용하는 사람이 해당 내용을 알고 있어야 하는 부분임. 또한 k8s 사용을 하고 있는 경우에 유용.
https://docs.gitlab.com/ee/topics/autodevops/index.html
코드 언어 감지
자동 빌드, 테스트, 코드 품질 측정
잠재적인 취약성, 보안 결함 및 라이선스 문제 스캔 (ultimate 에 해당)
실시간 모니터링
애플리케이션 배포
gitlab vs github
gitlab에서는 지원하지만 github에서는 지원하지 않는 기능들.
https://about.gitlab.com/devops-tools/github-vs-gitlab/ci-missing-github-capabilities/
staging, prod 에 따라 워크플로 다르게 실행하는 기능.
Cannot easily trigger different workflows for staging and production environment
Making secrets availabe to builds of forks
gitlab runner 설치 및 등록
사전에 docker를 먼저 설치해둔다.
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli http://containerd.io
# sudo docker run hello-world
gitlab runner 설치 및 등록
runner type : shared runners, group runners, specific runners
OS에 gitlab-runner 설치.
https://docs.gitlab.com/runner/install/linux-manually.html
curl -LJO https://gitlab-runner-downloads.s3.amazonaws.com/latest/deb/gitlab-runner_amd64.deb
dpkg -i gitlab-runner_amd64.deb
executor 가 여러 가지 있는데 docker 를 추천하고 있음. OS에 docker 설치.
gitlab-runner 설치 후 runner 를 등록함.
https://docs.gitlab.com/runner/register/index.html#docker
executor docker 로 실행시 VM에서 테스팅을 하는 경우 수동으로 설정한 호스트인 gitlab.example.com 을 찾지 못함.
REGISTRATION_TOKEN=gCGg8tkK51TATVpjsBHz
sudo gitlab-runner register \
--non-interactive \
--url http://gitlab.example.com/ \
--registration-token $REGISTRATION_TOKEN \
--executor "docker" \
--docker-image alpine:latest \
--description "docker-runner" \
--tag-list "docker,aws" \
--run-untagged="true" \
--locked="false" \
--access-level="not_protected"
https://docs.gitlab.com/runner/configuration/advanced-configuration.html
extra_hosts 옵션을 추가해서 docker 에서 /etc/hosts를 업데이트할 수 있음.
extra_hosts = ["other-host:127.0.0.1"]
cat > /tmp/test-config.template.toml << EOF
[[runners]]
name = "docker-runner"
[runners.docker]
extra_hosts = ["gitlab.example.com:192.168.33.12"]
EOF
REGISTRATION_TOKEN=gCGg8tkK51TATVpjsBHz
sudo gitlab-runner register \
--non-interactive \
--url http://gitlab.example.com/ \
--registration-token $REGISTRATION_TOKEN \
--executor "docker" \
--docker-image alpine:latest \
--description "docker-runner" \
--tag-list "docker,aws" \
--run-untagged="true" \
--locked="false" \
--access-level="not_protected" \
--template-config /tmp/test-config.template.toml
--run-untagged="true" 기본.
--locked="true" 기본
--access-level="not_protected" 기본.
아래는 SaaS 이용하는 경우임.
REGISTRATION_TOKEN=xxxxx
sudo gitlab-runner register \
--non-interactive \
--url https://gitlab.com/ \
--registration-token $REGISTRATION_TOKEN \
--executor "docker" \
--docker-image alpine:latest \
--description "docker-runner" \
--tag-list "docker,aws" \
--run-untagged="true" \
--locked="false" \
--access-level="not_protected"
REGISTRATION_TOKEN=xxxxx
sudo gitlab-runner register \
--url https://gitlab.com/ \
--registration-token $REGISTRATION_TOKEN \
--executor "shell" \
--docker-image ubuntu \
--description "shell-runner" \
--tag-list "deploy, nginx, review-apps" \
--run-untagged="true" \
--locked="false" \
--access-level="not_protected"
runner 에서 동시작업을 하려고 하면 gitlab-runner에서 concurrent 옵션을 바꾸어준다. 기본은 1로 되어 있다. 이 부분을 바꾸어 주어야 여러개의 job을 동시에 실행할 수 있다.
https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-global-section
gitlab runner 윈도우 서버
gitlab windows shared runner 제공은 하지만 아직 베타버전임.
https://about.gitlab.com/blog/2020/01/21/windows-shared-runner-beta/
windows runner 설치.
https://docs.gitlab.com/runner/install/windows.html
GCP에 windows runner 설치하여 사용하는 법
https://docs.gitlab.com/ee/development/windows.html
gitlab windows shared runner 에서 dotnetcore 사용하는 예제. build, test 있음.
https://gitlab.com/tobiaskoch/gitlab-ci-example-dotnetcore-windows
자세한 내용은 모르지만 fork 해서 실행을 하니 돌아는 갔음.
다른 툴과 연동
gitlab 에는 CICD 기능 외에 다양한 부가 기능을 많이 지원함.
애플리케이션 운영 및 유지 관리에 도움이되는 다양한 도구를 제공 https://docs.gitlab.com/ee/operations/
메트릭으로 신뢰성 및 안정성 측정
경고 및 사고 관리
애플리케이션의 오류 추적
애플리케이션 상태 및 성능 추적
로그 집계 및 저장
코드로 인프라 관리 (terraform remote backend)
k8s 통합기능
gitlab에서는 여러 가지 부가기능을 많이 지원하지만 github 에서는 다른 대체수단을 이용하여 처리할 수 있을 것으로 생각이 됨.
terraform remote backend 는 AWS 에서 s3+dynamoDB 와 연동하여 처리 가능
k8s는 Flux(https://fluxcd.io/ ) 나 Argo CD (https://argoproj.github.io/argo-cd/ ) 등을 이용하여 처리
docker registry
docker login http://registry.gitlab.com -u tjmoon
docker build -t http://registry.gitlab.com/vntg1/test:latest -t http://registry.gitlab.com/vntg1/test:0.1 .
docker build -t http://registry.gitlab.com/vntg1/test:latest -t http://registry.gitlab.com/vntg1/test:0.2 .
docker build -t http://registry.gitlab.com/vntg1/test:latest -t http://registry.gitlab.com/vntg1/test:0.3 .
docker push --all-tags http://registry.gitlab.com/vntg1/test