Socket for Gitlab Pipeline
Socket fights vulnerabilities and provides visibility, defense-in-depth, and proactive supply chain protection for your open source dependencies. It is easy to integrate Socket into your Gitlab Pipeline to provide an extra layer of security against Supply Chain Attacks.
Adding Socket to your pipeline
Create your Socket API Key
You can either create your API Key yourself if you have permissions in your socket.dev account or you can have your Admin create it for you with the Reports scope.
-
Log into the socket.dev dashboard
-
Go to Settings
-
Go to the API Tokens tab
-
Select Create API Token
-
Give the token a name like Gitlab API Token
-
Select the report, repo, and full-scans Scopes
-
Click Confirm
-
Click on Show key
-
Click on the API Token to copy
Create your Socket Environment variables
-
Log into Gitlab
-
Navigate to your project
-
Go to Settings -> CI/CD
-
Expand Variables
-
Do Add Variable
- Select Mask Variable
- Key: SOCKET_SECURITY_API_KEY
- Value: Socket API Token
-
Create a new variable for your Gitlab Token that has access to the Project
-
Key:
GITLAB_TOKEN
-
Value: gitlab_token_with_access
Example Gitlab Pipeline Setup
-
Go to Build
-
Go to Pipeline Editor
-
Paste the following Pipeline Yaml, or integrate with your existing code
test: image: socketdev/cli:latest rules: - when: always script: - socketcli --repo $CI_PROJECT_NAME --branch $(if [ -z $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME ]; then echo "$CI_COMMIT_BRANCH"; else echo "$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME"; fi) --target_path $CI_PROJECT_DIR --committer "$(echo $CI_COMMIT_AUTHOR | awk -F '<' '{print $2}' | head -c -2)" --commit_message "$CI_COMMIT_MESSAGE" --pr_number $(if [ -z $CI_MERGE_REQUEST_IID ]; then echo 0; else echo $CI_MERGE_REQUEST_IID; fi) --scm gitlab $(if [ "$CI_DEFAULT_BRANCH" == "$CI_COMMIT_BRANCH" ] || [ "$CI_DEFAULT_BRANCH" == "$CI_COMMIT_REF_NAME" ]; then echo --default_branch; fi)
-
Commit changes to your main branch or the current branch you are working on
Testing pipeline
-
Create a new branch
-
Modify or add a
package.json
-
Create a new Merge request
-
Confirm that the Socket CI pipeline job ran
-
Confirm that for an unhealthy report a comment is left on the Merge request
Updated 5 months ago
That's it! You're all done now any time there is an update to your manifest file the Socket CI will automatically run. You can update the criteria to add more things like requirements.txt
or other lock files.