Skip to content

Commit 2c18eaa

Browse files
authored
update 4x branch 20240513 (#4022)
Update for v4.5.4 release.
1 parent 9d42292 commit 2c18eaa

File tree

18 files changed

+603
-305
lines changed

18 files changed

+603
-305
lines changed

.ci/Makefile

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
SHELL = /bin/bash -eo pipefail
22
MAKEFLAGS += --no-print-directory
33
AWS_FOLDER = ../build/aws
4-
DIST_DIR = /build/dist/nodejs
54
LAMBDA_LAYER_ZIP_FILE = ../build/dist/elastic-apm-node-lambda-layer.zip
6-
DOCKER_IMAGE_NAME = observability/apm-agent-nodejs
7-
DOCKER_REGISTRY = docker.elastic.co
85
SUFFIX_ARN_FILE = arn-file.md
96
AGENT_VERSION = $(subst v,,$(GITHUB_REF_NAME))
107
MAJOR_VERSION = $(shell cut -d '.' -f 1 <<< $(AGENT_VERSION))
@@ -35,14 +32,6 @@ clean:
3532
env:
3633
@env | sort
3734

38-
# Create Docker image
39-
build-docker: validate-version
40-
docker build -t $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(AGENT_VERSION) \
41-
--build-arg AGENT_DIR=$(DIST_DIR) ..
42-
43-
push-docker: build-docker
44-
../dev-utils/push-docker.sh $(DOCKER_REGISTRY) $(DOCKER_IMAGE_NAME) $(AGENT_VERSION)
45-
4635
# List all the AWS regions
4736
get-all-aws-regions:
4837
@mkdir -p $(AWS_FOLDER)
@@ -99,11 +88,6 @@ create-arn-file: validate-release-notes-url
9988
github-release: validate-ref-name
10089
../dev-utils/github-release.sh "$(GITHUB_REF_NAME)" "$(AWS_FOLDER)/$(SUFFIX_ARN_FILE)"
10190

102-
validate-version:
103-
ifndef AGENT_VERSION
104-
$(error AGENT_VERSION is undefined)
105-
endif
106-
10791
validate-ref-name:
10892
ifndef GITHUB_REF_NAME
10993
$(error GITHUB_REF_NAME is undefined)

.ci/tav.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"versions": [ "21", "20", "18", "16", "14" ],
2+
"versions": [ "22", "20", "18", "16", "14" ],
33
"// modules": [
44
"List of instrumented modules with the minimum Node major version supported.",
55
"minMajorVersion for each module should be kept in sync with .tav.yml"

.github/workflows/edge.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
strategy:
3333
fail-fast: false
3434
matrix:
35-
node: [ "22" ]
35+
node: [ "23" ]
3636
steps:
3737
- uses: actions/checkout@v4
3838
- run: .ci/scripts/test.sh -b "nightly" "${{ matrix.node }}"
@@ -50,7 +50,8 @@ jobs:
5050
fail-fast: false
5151
matrix:
5252
node:
53-
- "21"
53+
- "23"
54+
- "22"
5455
- "20"
5556
- "18"
5657
steps:

.github/workflows/release.yml

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@ on:
44
push:
55
tags:
66
- v*.*.*
7+
branches:
8+
- main
79

810
permissions:
11+
attestations: write
912
contents: write
13+
id-token: write
1014
pull-requests: read
1115

1216
jobs:
1317
release:
1418
runs-on: ubuntu-latest
19+
env:
20+
DOCKER_IMAGE_NAME: docker.elastic.co/observability/apm-agent-nodejs
1521
steps:
1622
- uses: actions/checkout@v4
1723
with:
@@ -33,7 +39,41 @@ jobs:
3339

3440
- run: make -C .ci dist
3541

36-
- run: make -C .ci push-docker
42+
- name: Attest Lambda layer zip
43+
uses: github-early-access/generate-build-provenance@main
44+
with:
45+
subject-path: "${{ github.workspace }}/build/aws/elastic-apm-node-lambda-layer-*.zip"
46+
47+
- name: Extract metadata (tags, labels)
48+
id: docker-meta
49+
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
50+
with:
51+
images: ${{ env.DOCKER_IMAGE_NAME }}
52+
flavor: |
53+
latest=auto
54+
tags: |
55+
# "1.2.3" and "latest" Docker tags on push of git tag "v1.2.3"
56+
type=semver,pattern={{version}}
57+
# "edge" Docker tag on git push to default branch
58+
type=edge
59+
60+
- name: Build and Push Docker Image
61+
id: docker-push
62+
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
63+
with:
64+
context: .
65+
push: true
66+
tags: ${{ steps.docker-meta.outputs.tags }}
67+
labels: ${{ steps.docker-meta.outputs.labels }}
68+
build-args: |
69+
AGENT_DIR=/build/dist/nodejs
70+
71+
- name: Attest Docker image
72+
uses: github-early-access/generate-build-provenance@main
73+
with:
74+
subject-name: "${{ env.DOCKER_IMAGE_NAME }}"
75+
subject-digest: ${{ steps.docker-push.outputs.digest }}
76+
push-to-registry: true
3777

3878
- name: Read AWS vault secrets
3979
uses: hashicorp/[email protected]
@@ -46,12 +86,15 @@ jobs:
4686
secret/observability-team/ci/service-account/apm-aws-lambda access_key_id | AWS_ACCESS_KEY_ID ;
4787
secret/observability-team/ci/service-account/apm-aws-lambda secret_access_key | AWS_SECRET_ACCESS_KEY
4888
49-
- name: Publish AWS lambda
89+
- name: Publish AWS lambda (only for tag release)
90+
if: startsWith(github.ref, 'refs/tags')
5091
run: make -C .ci publish-in-all-aws-regions create-arn-file
5192
env:
5293
GH_TOKEN: ${{ github.token }}
5394

54-
- run: make -C .ci github-release
95+
- name: create github release (only for tag release)
96+
run: make -C .ci github-release
97+
if: startsWith(github.ref, 'refs/tags')
5598
env:
5699
GH_TOKEN: ${{ github.token }}
57100

@@ -66,12 +109,13 @@ jobs:
66109
secret/jenkins-ci/npmjs/elasticmachine token | NPMJS_TOKEN ;
67110
totp/code/npmjs-elasticmachine code | TOTP_CODE
68111
69-
- name: npm publish
112+
- name: npm publish (only for tag release)
113+
if: startsWith(github.ref, 'refs/tags')
70114
run: |-
71115
echo "//registry.npmjs.org/:_authToken=${{ env.NPMJS_TOKEN }}" > .npmrc
72-
npm publish --otp=${{ env.TOTP_CODE }}
116+
npm publish --otp=${{ env.TOTP_CODE }} --provenance
73117
74-
- if: always()
118+
- if: ${{ always() && startsWith(github.ref, 'refs/tags') }}
75119
uses: elastic/apm-pipeline-library/.github/actions/notify-build-status@current
76120
with:
77121
vaultUrl: ${{ secrets.VAULT_ADDR }}

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ jobs:
133133
- "2181:2181"
134134
volumes:
135135
- nodezookeeperdata:/var/lib/zookeeper/data
136-
136+
137137
kafka:
138138
image: bitnami/kafka:3.3.2
139139
ports:
@@ -154,8 +154,8 @@ jobs:
154154
fail-fast: false
155155
matrix:
156156
node:
157-
- '21'
158-
- '21.0'
157+
- '22'
158+
- '22.0'
159159
- '20'
160160
- '20.0'
161161
- '18'

CHANGELOG.asciidoc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,38 @@ Notes:
3333
3434
See the <<upgrade-to-v4>> guide.
3535
36+
[[release-notes-4.5.4]]
37+
==== 4.5.4 - 2024/05/13
38+
39+
[float]
40+
===== Bug fixes
41+
42+
- Change how the "cookie" HTTP request header is represented in APM transaction
43+
data to avoid a rare, but possible, intake bug where the transaction could be
44+
rejected due to a mapping conflict.
45+
46+
Before this change a `Cookie: foo=bar; sessionid=42` HTTP request header
47+
would be represented in the transaction document in Elasticsearch with these
48+
document fields (the example assumes <<sanitize-field-names>> matches
49+
"sessionid", as it does by default):
50+
51+
```
52+
http.request.headers.cookie: "[REDACTED]"
53+
...
54+
http.request.cookies.foo: "bar"
55+
http.request.cookies.sessionid: "[REDACTED]"
56+
```
57+
58+
After this change it is represented as:
59+
60+
```
61+
http.request.headers.cookie: "foo=bar; sessionid=REDACTED"
62+
```
63+
64+
In other words, `http.request.cookies` are no longer separated out.
65+
({issues}4006[#4006])
66+
67+
3668
[[release-notes-4.5.3]]
3769
==== 4.5.3 - 2024/04/23
3870

dev-utils/push-docker.sh

Lines changed: 0 additions & 32 deletions
This file was deleted.

lib/filters/sanitize-field-names.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,17 @@ function redactKeysFromPostedFormVariables(body, requestHeaders, regexes) {
4848
*
4949
* @param {Object} obj The source object be copied with redacted fields
5050
* @param {Array<RegExp>} regexes RegExps to check if the entry value needd to be redacted
51+
* @param {String} redactedStr The string to use for redacted values. Defaults to '[REDACTED]'.
5152
* @returns {Object} Copy of the source object with REDACTED entries or the original if falsy or regexes is not an array
5253
*/
53-
function redactKeysFromObject(obj, regexes) {
54+
function redactKeysFromObject(obj, regexes, redactedStr = REDACTED) {
5455
if (!obj || !Array.isArray(regexes)) {
5556
return obj;
5657
}
5758
const result = {};
5859
for (const key of Object.keys(obj)) {
5960
const shouldRedact = regexes.some((regex) => regex.test(key));
60-
result[key] = shouldRedact ? REDACTED : obj[key];
61+
result[key] = shouldRedact ? redactedStr : obj[key];
6162
}
6263
return result;
6364
}

lib/parsers.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ const {
2020
redactKeysFromPostedFormVariables,
2121
} = require('./filters/sanitize-field-names');
2222

23+
// When redacting individual cookie field values, this string is used instead
24+
// of `[REDACTED]`. The APM spec says:
25+
// > The replacement string SHOULD be `[REDACTED]`.
26+
// We diverge from spec here because, for better or worse, the `cookie` module
27+
// does `encodeURIComponent/decodeURIComponent` encoding on cookie fields. If we
28+
// used the brackets, then the reconstructed cookie would look like
29+
// `foo=bar; session-id=%5BREDACTED%5D`, which isn't helpful.
30+
const COOKIE_VAL_REDACTED = 'REDACTED';
31+
2332
/**
2433
* Extract appropriate `{transaction,error}.context.request` from an HTTP
2534
* request object. This handles header and body capture and redaction
@@ -61,14 +70,21 @@ function getContextFromRequest(req, conf, type) {
6170
conf.sanitizeFieldNamesRegExp,
6271
);
6372

64-
if (context.headers.cookie) {
65-
context.cookies = cookie.parse(req.headers.cookie);
66-
context.cookies = redactKeysFromObject(
67-
context.cookies,
73+
if (context.headers.cookie && context.headers.cookie !== REDACTED) {
74+
let cookies = cookie.parse(req.headers.cookie);
75+
cookies = redactKeysFromObject(
76+
cookies,
6877
conf.sanitizeFieldNamesRegExp,
78+
COOKIE_VAL_REDACTED,
6979
);
70-
// Redact the cookie to avoid data duplication
71-
context.headers.cookie = REDACTED;
80+
try {
81+
context.headers.cookie = Object.keys(cookies)
82+
.map((k) => cookie.serialize(k, cookies[k]))
83+
.join('; ');
84+
} catch (_err) {
85+
// Fallback to full redaction if there is an issue re-serializing.
86+
context.headers.cookie = REDACTED;
87+
}
7288
}
7389
}
7490

0 commit comments

Comments
 (0)