Concourse Lab Creation

从零开始学习 AWS 黑客技术直至成为专家,通过 htARTE (HackTricks AWS 红队专家)

支持 HackTricks 的其他方式:

测试环境

运行 Concourse

使用 Docker-Compose

此 docker-compose 文件简化了安装过程,便于进行一些 concourse 的测试:

wget https://raw.githubusercontent.com/starkandwayne/concourse-tutorial/master/docker-compose.yml
docker-compose up -d

您可以从网页 127.0.0.1:8080 下载适用于您操作系统的命令行工具 fly

使用 Kubernetes(推荐)

您可以使用 helm-chart:concourse-chartKubernetes(例如在 minikube 中)中轻松部署 concourse。

brew install helm
helm repo add concourse https://concourse-charts.storage.googleapis.com/
helm install concourse-release concourse/concourse
# concourse-release will be the prefix name for the concourse elements in k8s
# After the installation you will find the indications to connect to it in the console

# If you need to delete it
helm delete concourse-release

生成 concourse 环境后,您可以生成一个密钥,并授权 concourse web 中运行的 SA 访问 K8s 密钥:

echo 'apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: read-secrets
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get"]

---

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: read-secrets-concourse
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: read-secrets
subjects:
- kind: ServiceAccount
name: concourse-release-web
namespace: default

---

apiVersion: v1
kind: Secret
metadata:
name: super
namespace: concourse-release-main
type: Opaque
data:
secret: MWYyZDFlMmU2N2Rm

' | kubectl apply -f -

创建 Pipeline

Pipeline 由一系列 Jobs 组成,其中包含有序的 Steps 列表。

Steps

可以使用几种不同类型的 steps:

每个 job 计划 中的 步骤 都在自己的容器中运行。你可以在容器内运行任何你想要的东西 (例如,运行我的测试,运行这个 bash 脚本,构建这个镜像等)。所以,如果你有一个包含五个步骤的 job,Concourse 将创建五个容器,每个步骤一个。

因此,可以指定每个步骤需要运行在哪种类型的容器中。

简单 Pipeline 示例

jobs:
- name: simple
plan:
- task: simple-task
privileged: true
config:
# Tells Concourse which type of worker this task should run on
platform: linux
image_resource:
type: registry-image
source:
repository: busybox # images are pulled from docker hub by default
run:
path: sh
args:
- -cx
- |
sleep 1000
echo "$SUPER_SECRET"
params:
SUPER_SECRET: ((super.secret))
fly -t tutorial set-pipeline -p pipe-name -c hello-world.yml
# pipelines are paused when first created
fly -t tutorial unpause-pipeline -p pipe-name
# trigger the job and watch it run to completion
fly -t tutorial trigger-job --job pipe-name/simple --watch
# From another console
fly -t tutorial intercept --job pipe-name/simple

检查 127.0.0.1:8080 查看管道流程。

Bash 脚本与输出/输入管道

可以将一个任务的结果保存在文件中,并指明它是一个输出,然后将下一个任务的输入指定为前一个任务的输出。Concourse 会做的是将前一个任务的目录挂载到新任务中,你可以访问前一个任务创建的文件

触发器

你不需要每次都手动触发作业,你也可以设置它们在以下情况自动运行:

查看一个在主分支有新提交时触发的 YAML 管道示例,请访问 https://concourse-ci.org/tutorial-resources.html

从零开始学习 AWS 黑客技术,成为英雄级人物,通过 htARTE (HackTricks AWS 红队专家)

支持 HackTricks 的其他方式:

Last updated