Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: NewDocker File and Pipelins #276

Open
wants to merge 81 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
b809c63
Added basic execution for code scan
luarredo Jul 11, 2024
c1ba25c
Improved code execution and flow
luarredo Jul 11, 2024
817f8a5
IDE initial implementations
luarredo Jul 25, 2024
e497736
updated git ignore
luarredo Jul 25, 2024
067a49e
Merge branch 'trunk' of https://github.com/bancolombia/NU0429001_devs…
luarredo Jul 25, 2024
97fbb22
Report sonar migrated to new folders structure
luarredo Jul 25, 2024
77a4a01
Merge branch 'trunk' of https://github.com/bancolombia/NU0429001_devs…
luarredo Aug 1, 2024
8a47429
Sonarqube adjust
luarredo Aug 5, 2024
6bbeb4a
Updated dockerfile
luarredo Aug 8, 2024
acb6880
chore: Update devsecops scanner Docker image version to 1.8.7
luarredo Sep 2, 2024
13ae196
feat: Code refactor to implement clean architechture
luarredo Sep 2, 2024
458fa69
chore: Update devsecops scanner Docker image version to 1.8.7
luarredo Sep 2, 2024
a7bfa1a
feature: Varible replacing implemented
luarredo Sep 2, 2024
3fb3a7f
Save
luarredo Sep 19, 2024
cda4b70
Update remote repo
luarredo Oct 6, 2024
67d91b2
Replacer per release id
luarredo Oct 7, 2024
5c74d97
chore: Remove unused Dockerfiles and Kubernetes manifests
luarredo Oct 7, 2024
baa76e0
Merge branch 'trunk' of https://github.com/bancolombia/devsecops-engi…
luarredo Oct 7, 2024
fb47b79
Needed files
luarredo Oct 7, 2024
9b8fbe0
Merge branch 'trunk' of https://github.com/bancolombia/devsecops-engi…
luarredo Oct 24, 2024
c59af37
Updates to dockerfile for remote config
luarredo Oct 26, 2024
79ff2f9
chore: Update Dockerfile for remote config and fix exclusions in engi…
luarredo Oct 31, 2024
8d2837e
chore: Update Dockerfile for remote config and fix exclusions in engi…
luarredo Nov 14, 2024
b8252d9
Set up CI with Azure Pipelines
luarredo Nov 27, 2024
643b001
Update azure-pipelines.yml for Azure Pipelines
luarredo Nov 27, 2024
a72cbb5
Update azure-pipelines.yml for Azure Pipelines
luarredo Nov 27, 2024
8c0ef69
feat: Update Dockerfile for remote config and fix exclusions in engin…
luarredo Nov 27, 2024
6525619
Merge branch 'feature/CustomDocker' of https://github.com/bancolombia…
luarredo Nov 27, 2024
fc03778
Update azure-pipelines.yml for Azure Pipelines
luarredo Dec 3, 2024
6e131e6
chore: Update Dockerfile to include remote config and fix exclusions …
luarredo Dec 3, 2024
c602ab4
Merge branch 'feature/CustomDocker' of https://github.com/bancolombia…
luarredo Dec 3, 2024
a809286
chore: Update azure-pipelines.yml to include PythonScript tasks for g…
luarredo Dec 3, 2024
1a2c267
chore: Fix typo in azure-pipelines.yml
luarredo Dec 4, 2024
763d046
Update azure-pipelines.yml to include PythonScript task for getting f…
luarredo Dec 4, 2024
0fe933d
chore: Update azure-pipelines.yml to use correct script names for Pyt…
luarredo Dec 4, 2024
e2f36b5
chore: Add script to print current directory and list files
luarredo Dec 4, 2024
ab1f894
chore: Update azure-pipelines.yml to include PythonScript task for te…
luarredo Dec 4, 2024
e7f8ce5
chore: Update azure-pipelines.yml to use correct script paths for Pyt…
luarredo Dec 4, 2024
bc262a5
chore: Update azure-pipelines.yml to use PythonScript tasks for getti…
luarredo Dec 4, 2024
81ca15e
chore: Add PythonScript task to test Felipe's changes
luarredo Dec 4, 2024
2154e12
chore: Update azure-pipelines.yml to include PythonScript task for te…
luarredo Dec 5, 2024
6827e2a
Update azure-pipelines.yml for Azure Pipelines
luarredo Dec 5, 2024
655a306
Update azure-pipelines.yml for Azure Pipelines
luarredo Dec 5, 2024
b73b248
Update azure-pipelines.yml for Azure Pipelines
luarredo Dec 5, 2024
07a0543
Update azure-pipelines.yml for Azure Pipelines
luarredo Dec 11, 2024
c7c1eb8
Update azure-pipelines.yml for Azure Pipelines
luarredo Dec 12, 2024
0674be4
Dockerfile base image update
luarredo Dec 12, 2024
92c3069
Update azure-pipelines.yml for Azure Pipelines
luarredo Dec 12, 2024
8583242
Update azure-pipelines.yml for Azure Pipelines
luarredo Dec 12, 2024
9380ea5
Update azure-pipelines.yml for Azure Pipelines
luarredo Dec 12, 2024
95c6986
chore: Update Dockerfile base image to specific SHA256 hash
luarredo Dec 12, 2024
8c5e323
chore: Update Dockerfile and azure-pipelines.yml for Azure Pipelines
luarredo Dec 12, 2024
73c6450
chore: Update Dockerfile and azure-pipelines.yml for Azure Pipelines
luarredo Dec 12, 2024
d5f70bd
Update azure-pipelines.yml for Azure Pipelines
luarredo Dec 12, 2024
cca3765
Update azure-pipelines.yml for Azure Pipelines
luarredo Dec 12, 2024
88f6cf7
Update azure-pipelines.yml for Azure Pipelines
luarredo Dec 12, 2024
18a178f
Update azure-pipelines.yml for Azure Pipelines
luarredo Dec 12, 2024
d1ea597
chore: Update Dockerfile to fix file path in COPY command
luarredo Dec 12, 2024
75d4e9c
chore: Update Dockerfile and azure-pipelines.yml to use specific vers…
luarredo Dec 12, 2024
9552ff9
chore: Update azure-pipelines.yml to use 'bancolombia/devsecops-engin…
luarredo Dec 12, 2024
625dd31
chore: Update Dockerfile and azure-pipelines.yml to use 'artifactory.…
luarredo Dec 12, 2024
6435ec5
chore: Update azure-pipelines.yml to use specific version 1.25.1
luarredo Dec 12, 2024
59a1224
chore: Download and save Azure DevOps folder content as JSON file
luarredo Dec 12, 2024
5c0c655
chore: Update get_files_ad.py to include external checks directory flag
luarredo Dec 12, 2024
ba588f2
chore: Update Dockerfile and Docker Compose to include Trivy vulnerab…
luarredo Dec 12, 2024
00b03e4
chore: Update get_files_ad.py to include external checks directory flag
luarredo Dec 12, 2024
ff1881d
chore: Update get_files_ad.py to include download_path argument
luarredo Dec 12, 2024
8475a7a
chore: Update azure-pipelines.yml to set lib version from version.py …
luarredo Dec 17, 2024
3e19244
chore: Update azure-pipelines.yml to set lib version from version.py …
luarredo Dec 17, 2024
7704f21
chore: Update azure-pipelines.yml to set lib version from version.py …
luarredo Dec 17, 2024
c501c91
chore: Update azure-pipelines.yml to use the release version for Dock…
luarredo Dec 17, 2024
67d8b48
Merge branch 'trunk' of https://github.com/bancolombia/devsecops-engi…
luarredo Dec 17, 2024
6b022cd
chore: Remove unused files and configurations
luarredo Dec 17, 2024
60453fd
Update get_files_gh.py to remove unnecessary comments and extra white…
luarredo Dec 17, 2024
46e3d55
chore: Update GET_IMAGE_BASE value to false in ConfigTool.json
luarredo Dec 17, 2024
2e612af
chore: Update Exclusions.json formatting
luarredo Dec 17, 2024
9a36845
chore: Update IacScanner to use devsecops-engine-tools image without …
luarredo Dec 17, 2024
8fa788a
chore: Update ImageScanner to use devsecops-engine-tools image withou…
luarredo Dec 17, 2024
35469b1
Changed name to yml pipeline and moved folder
luarredo Jan 7, 2025
8f27921
Comments resolved
luarredo Jan 7, 2025
db975c1
Deleted file
luarredo Jan 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
with:
app_id: ${{ secrets.APP_ID_ADMIN_GITHUB }}
private_key: ${{ secrets.APP_PRIVATE_KEY_ADMIN_GITHUB }}

# Check out the current repository
- name: Fetch Sources
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
Expand Down
39 changes: 39 additions & 0 deletions azure-pipelines.yml
luarredo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

trigger:
- trunk
luarredo marked this conversation as resolved.
Show resolved Hide resolved

pool:
name: Azure Pipelines

steps:

- task: connect-agent@2
displayName: 'Hosted agent'
inputs:
hostedAgentService: 90469226-70c7-4fd9-acf1-a6f54739e00a
luarredo marked this conversation as resolved.
Show resolved Hide resolved

- script: |
version=$(python3 -c "import sys; sys.path.append('tools/devsecops_engine_tools'); import version; print(version.version)")
echo "##vso[task.setvariable variable=RELEASE_VERSION]$version"
luarredo marked this conversation as resolved.
Show resolved Hide resolved
displayName: 'Set lib version from version.py'

- script: echo "Release version is $(RELEASE_VERSION)"
displayName: 'Use the release version'

- script: python3 docker/get_files_ad.py $(repo-owner-ad) "$(project-ad)" NU0429001_DevSecOps_Remote_Config /engine_sast/engine_iac/ConfigTool.json $(ad-at) path
luarredo marked this conversation as resolved.
Show resolved Hide resolved
displayName: 'Get Custom Remote Config'

- script: python3 docker/get_files_gh.py $(repo-owner) $(project) rules $(gh-at) rules
displayName: 'Get Custom IAC Rules'

- script: docker build --build-arg VERSION=$(RELEASE_VERSION) -t artifactory.apps.bancolombia.com/devops/devsecops-engine-tools:$(RELEASE_VERSION) -f docker/Dockerfile . && docker tag artifactory.apps.bancolombia.com/devops/devsecops-engine-tools:$(RELEASE_VERSION) artifactory.apps.bancolombia.com/devops/devsecops-engine-tools:$(RELEASE_VERSION)
luarredo marked this conversation as resolved.
Show resolved Hide resolved
displayName: 'Build Docker Image'

- task: ArtifactoryDocker@1
displayName: Docker Push
inputs:
command: 'push'
repository: 'devops/devsecops-engine-tools'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handle the repository with variable

artifactoryService: 'Artifactory'
targetRepo: 'devops/devsecops-engine-tools'
imageName: 'artifactory.apps.bancolombia.com/devops/devsecops-engine-tools:$(RELEASE_VERSION)'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handle the url of artifactory with variable

376 changes: 376 additions & 0 deletions build.log
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file necessary?

Large diffs are not rendered by default.

33 changes: 32 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ WORKDIR /app
ARG VERSION
ENV APP_VERSION=$VERSION

ARG REMOTE_CONFIG="./example_remote_config_local"
ENV REMOTE_CONFIG_PATH=$REMOTE_CONFIG

ENV DET_PIPELINE_NAME="" \
DET_PATH_DIRECTORY="." \
DET_OS="Linux" \
Expand All @@ -28,8 +31,9 @@ ENV DET_PIPELINE_NAME="" \
RUN apt-get update && apt-get install -y bash
RUN apt-get update && apt-get install -y dos2unix

COPY ./example_remote_config_local /app/example_remote_config_local
COPY $REMOTE_CONFIG /app/example_remote_config_local
COPY ./docker/remoteConfigGeneration.sh /app/remoteConfigGeneration.sh
COPY ./rules* /tmp/rules

RUN dos2unix /app/remoteConfigGeneration.sh

Expand All @@ -43,11 +47,38 @@ RUN apt-get update && \
python3-venv \
python3-pip

# Update and install prerequisites
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates \
curl && \
rm -rf /var/lib/apt/lists/*

# Add Docker’s official GPG key
RUN install -m 0755 -d /etc/apt/keyrings && \
curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc && \
chmod a+r /etc/apt/keyrings/docker.asc

# Add Docker repository to APT sources
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo \"$VERSION_CODENAME\") stable" \
| tee /etc/apt/sources.list.d/docker.list > /dev/null

# Update package list and install Docker
RUN apt-get update && \
apt-get install -y --no-install-recommends \
docker-ce \
docker-ce-cli \
containerd.io \
docker-buildx-plugin \
docker-compose-plugin && \
rm -rf /var/lib/apt/lists/*

RUN ln -s /usr/bin/python3 /usr/local/bin/python3 && \
ln -s /usr/bin/pip3 /usr/local/bin/pip3

RUN python3 -m venv venv
RUN python3 -m pip install --break-system-packages checkov==2.3.296

RUN python3 -m pip install --break-system-packages -i https://pypi.org/simple devsecops-engine-tools==$APP_VERSION

CMD ["sh", "-c", "dockerd & while ! docker info > /dev/null 2>&1; do sleep 1; done; sh"]
43 changes: 43 additions & 0 deletions docker/get_files_ad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import requests
import sys
import json

def download_folder_from_azure_devops(organization, project, repository, path, token, download_path):
print(download_path)
url = f"https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repository}/items?scopePath={path}&recursionLevel=Full&api-version=7.1"
headers = {"Authorization": f"Basic {token}"}
response = requests.get(url, headers=headers)

if response.status_code == 200:
data = response.json()
data['CHECKOV']['USE_EXTERNAL_CHECKS_DIR'] = "True"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this modification is not necessary

content = str(json.dumps(data))
file_path = "example_remote_config_local/engine_sast/engine_iac/ConfigTool.json"
with open(file_path, "w") as file:
file.write(content)
print(f"File '{file_path}' downloaded successfully.")
else:
print(f"Error downloading folder. Status code: {response.status_code}")
print(response.text)

# Example usage
# organization = "your-organization"
# project = "your-project"
# repository = "your-repository"
# path = "path/to/your/folder"
# token = "your-personal-access-token"
# download_path = "."

if __name__ == "__main__":
if len(sys.argv) < 7:
print("Usage: python get_files_ad.py <organization> <project> <repository> <path> <token> <download_path>")
sys.exit(1)

organization = sys.argv[1]
project = sys.argv[2]
repository = sys.argv[3]
path = sys.argv[4] # path to download
token = sys.argv[5] # your personal access token
download_path = sys.argv[6]

download_folder_from_azure_devops(organization, project, repository, path, token, download_path)
49 changes: 49 additions & 0 deletions docker/get_files_gh.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of use api content of gihutb use /Users/sagavir/Documents/Repositorios/Github/devsecops-engine-tools/tools/devsecops_engine_tools/engine_utilities/github/infrastructure/github_api.py with the auth using private_key

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import requests
import os
import sys
from concurrent.futures import ThreadPoolExecutor

def download_folder_from_github(owner, repository, path, token, download_path):
url = f"https://api.github.com/repos/{owner}/{repository}/contents/{path}"
headers = {"Authorization": f"token {token}", "Accept": "application/vnd.github.v3.raw"}
response = requests.get(url, headers=headers)

if response.status_code == 200:
contents = response.json()
if isinstance(contents, list):
# It's a directory
with ThreadPoolExecutor(max_workers=5) as executor:
for item in contents:
item_path = item['path']
if item['type'] == 'file':
executor.submit(download_file_from_github, owner, repository, item_path, token, download_path)
elif item['type'] == 'dir':
new_download_path = os.path.join(download_path, os.path.basename(item_path))
os.makedirs(new_download_path, exist_ok=True)
executor.submit(download_folder_from_github, owner, repository, item_path, token, new_download_path)
else:
print(f"Error: Expected a directory but got a file at {path}")
else:
print(f"Error downloading folder. Status code: {response.status_code}")

def download_file_from_github(owner, repository, path, token, download_path="."):
url = f"https://api.github.com/repos/{owner}/{repository}/contents/{path}"
headers = {"Authorization": f"token {token}", "Accept": "application/vnd.github.v3.raw"}
response = requests.get(url, headers=headers)

if response.status_code == 200:
file_name = os.path.basename(path)
file_path = os.path.join(download_path, file_name)
with open(file_path, "wb") as file:
file.write(response.content)
print(f"File {file_name} downloaded successfully to {file_path}")
else:
print(f"Error downloading file. Status code: {response.status_code}")

owner = sys.argv[1]
repository = sys.argv[2]
path = sys.argv[3]
token = sys.argv[4]
download_path = sys.argv[5]

download_folder_from_github(owner, repository, path, token, download_path)
7 changes: 5 additions & 2 deletions docker/remoteConfigGeneration.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

mv /app/example_remote_config_local /app/docker_default_remote_config
json_file="/app/docker_default_remote_config/engine_core/ConfigTool.json"
sed -i 's/"TOOL": "CHECKOV|KUBESCAPE|KICS"/"TOOL": "CHECKOV"/' "$json_file"
json_file_iac="/app/docker_default_remote_config/engine_core/ConfigTool.json"
sed -i 's/"TOOL": "CHECKOV|KUBESCAPE|KICS"/"TOOL": "CHECKOV"/' "$json_file_iac"

json_file_container="/app/docker_default_remote_config/engine_core/ConfigTool.json"
sed -i 's/"TOOL": "PRISMA|TRIVY"/"TOOL": "TRIVY"/' "$json_file_container"
Loading
Loading