Skip to content

Commit 102b422

Browse files
add option to disable TLS cert validation (#87)
1 parent 396e11f commit 102b422

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

action.yaml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ name: 'codefresh-report-image'
22
description: 'Report image to codefresh'
33
inputs:
44
VERSION:
5-
description: specify client version
5+
description: Underling reporter image version used by plugin
66
required: false
77
default: latest
8+
IMAGE:
9+
description: Underling reporter image used by plugin
10+
required: false
11+
default: quay.io/codefresh/codefresh-report-image
812
CF_API_KEY:
913
description: "Codefresh API KEY"
1014
required: true
@@ -18,7 +22,7 @@ inputs:
1822
description: "Codefresh runtime name"
1923
required: true
2024
CF_VERBOSE:
21-
description: "verbose output"
25+
description: "Verbose output"
2226
required: false
2327
CF_IMAGE:
2428
description: "image reported, quay.io/codefresh/newly-built-image:0.0.1"
@@ -46,7 +50,7 @@ inputs:
4650
description: "Generic registry domain"
4751
CF_INSECURE:
4852
required: false
49-
description: "security flag for standard registry protocol, when set to true it enables http protocol"
53+
description: "Disable TLS certificate validation for ALL of the https traffic during the reporting. It is NOT recommended, as it could make your application vulnerable to man-in-the-middle (MITM) attacks."
5054
CF_WORKFLOW_URL:
5155
required: false
5256
description: "external url for the workflow"
@@ -118,21 +122,23 @@ runs:
118122
- shell: bash
119123
env:
120124
VERSION: "${{ inputs.VERSION }}"
125+
IMAGE: "${{ inputs.IMAGE }}"
126+
CF_VERBOSE: "${{ inputs.CF_VERBOSE }}"
121127
CF_HOST: "${{ inputs.CF_HOST }}"
122128
CF_PLATFORM_URL: "${{ inputs.CF_PLATFORM_URL }}"
123129
CF_RUNTIME_NAME: "${{ inputs.CF_RUNTIME_NAME }}"
124130
CF_API_KEY: "${{ inputs.CF_API_KEY }}"
131+
132+
CF_INSECURE: "${{ inputs.CF_INSECURE }}"
125133

126134
CF_IMAGE: "${{ inputs.CF_IMAGE }}"
127-
CF_VERBOSE: "${{ inputs.CF_VERBOSE }}"
128135
CF_CONTAINER_REGISTRY_INTEGRATION: "${{ inputs.CF_CONTAINER_REGISTRY_INTEGRATION }}"
129136
CF_ISSUE_TRACKING_INTEGRATION: "${{ inputs.CF_ISSUE_TRACKING_INTEGRATION }}"
130137
CF_DOCKERHUB_USERNAME: "${{ inputs.CF_DOCKERHUB_USERNAME }}"
131138
CF_DOCKERHUB_PASSWORD: "${{ inputs.CF_DOCKERHUB_PASSWORD }}"
132139
CF_REGISTRY_USERNAME: "${{ inputs.CF_REGISTRY_USERNAME }}"
133140
CF_REGISTRY_PASSWORD: "${{ inputs.CF_REGISTRY_PASSWORD }}"
134141
CF_REGISTRY_DOMAIN: "${{ inputs.CF_REGISTRY_DOMAIN }}"
135-
CF_INSECURE: "${{ inputs.CF_INSECURE }}"
136142
CF_WORKFLOW_URL: "${{ inputs.CF_WORKFLOW_URL }}"
137143
CF_WORKFLOW_NAME: "${{ inputs.CF_WORKFLOW_NAME }}"
138144
CF_LOGS_URL: "${{ inputs.CF_LOGS_URL }}"
@@ -178,7 +184,9 @@ runs:
178184
export CF_WORKFLOW_NAME="${CF_WORKFLOW_NAME:-$GITHUB_WORKFLOW_NAME}"
179185
export CF_GIT_PROVIDER="${CF_GIT_PROVIDER:-github}"
180186
export CF_CI_TYPE=github-actions
187+
188+
export NODE_TLS_REJECT_UNAUTHORIZED=$([[ "$CF_INSECURE" == "true" ]] && echo 0 || echo 1)
181189
182190
env | cut -f 1 -d "=" | grep -E "^CF_" > cf_env
183191
echo "Provided env vars: $(cat cf_env|xargs echo)"
184-
docker run --env-file=cf_env "quay.io/codefresh/codefresh-report-image:$VERSION"
192+
docker run -e NODE_TLS_REJECT_UNAUTHORIZED=$NODE_TLS_REJECT_UNAUTHORIZED --env-file=cf_env "$IMAGE:$VERSION"

service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
name: codefresh-report-image
2-
version: 0.0.158
2+
version: 0.0.159

src/logger.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ const paint = (kind, message) => {
1414
return message
1515
}
1616

17+
const debugEnabled = process.env.DEBUG === '1' || process.env.CF_VERBOSE === 'true'
1718

1819
export const logger = winston.createLogger({
1920
format: winston.format.printf((info) => {
2021
return paint(info.level, `${info.message}`)
2122
}),
22-
transports: [ new winston.transports.Console({ level: process.env.DEBUG === '1' ? 'debug' : 'info' }) ],
23+
transports: [ new winston.transports.Console({ level: debugEnabled ? 'debug' : 'info' }) ],
2324
})
2425

2526
export const workflowLogger = winston.createLogger({

src/main.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ const INITIAL_HEARTBEAT_TIMEOUT_IN_SEC = Number(process.env.INITIAL_HEARTBEAT_TI
1313
* Take (CF_ prefixed) Env variables and perform http/s request (SSE) to app-proxy for image-report with CF_ENRICHERS
1414
*/
1515
async function main(argv, env): Promise<void> {
16-
const verbose = argv.includes('verbose') || env['VERBOSE']
17-
if (verbose) {
18-
logger.debug('running with verbose log')
19-
}
2016
const payload = validate(env)
2117
const { url, headers } = await Utils.buildUrlHeaders(payload)
22-
if (verbose) {
23-
logger.debug(`payload: ${JSON.stringify(payload, null, 2)}`)
24-
logger.debug(`sending request: ${url}, headers: ${JSON.stringify(headers)}`)
25-
}
18+
19+
logger.debug(`skip TLS verification on client: ${env['NODE_TLS_REJECT_UNAUTHORIZED'] === '0'}`)
20+
logger.debug(`skip TLS verification on workflow: ${env['CF_INSECURE'] === 'true'}`)
21+
logger.debug(`payload: ${JSON.stringify(payload, null, 2)}`)
22+
logger.debug(`sending request: ${url}, headers: ${JSON.stringify(headers)}`)
23+
2624
if (payload['CF_CI_TYPE'] && payload['CF_WORKFLOW_URL']) {
2725
logger.info(`CI provider: ${payload['CF_CI_TYPE']}, job URL: ${payload['CF_WORKFLOW_URL']}`)
2826
}

0 commit comments

Comments
 (0)