Skip to content

Commit ead1604

Browse files
authored
fix(rcm): error in capabilities (#5170)
## Checklist Error in capabilities. If we set DD_APPSEC_ENABLED env var, we don't report capabilities in RC requests - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/contributing.html#Release-Note-Guidelines) are followed. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Author is aware of the performance implications of this PR as reported in the benchmarks PR comment. ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer is aware of, and discussed the performance implications of this PR as reported in the benchmarks PR comment.
1 parent d5533b9 commit ead1604

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

ddtrace/appsec/utils.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,20 @@ def _appsec_rc_capabilities():
3939
256 -> 100000000 -> b'\x01\x00' -> b'AQA='
4040
"""
4141
value = 0b0
42-
43-
if _appsec_rc_features_is_enabled():
44-
value |= 1 << 1
45-
value |= 1 << 2
46-
47-
if sys.version_info.major < 3:
48-
bytes_res = to_bytes_py2(value, (value.bit_length() + 7) // 8, "big")
49-
# "type: ignore" because mypy does not notice this is for Python2 b64encode
50-
result = str(base64.b64encode(bytes_res)) # type: ignore
51-
else:
52-
result = str(base64.b64encode(value.to_bytes((value.bit_length() + 7) // 8, "big")), encoding="utf-8")
42+
result = ""
43+
if asbool(os.environ.get("DD_REMOTE_CONFIGURATION_ENABLED", "true")) or asbool(os.environ.get(APPSEC_ENV)):
44+
if _appsec_rc_features_is_enabled():
45+
value |= 1 << 1 # Enable ASM_ACTIVATION
46+
value |= 1 << 2 # Enable ASM_IP_BLOCKING
47+
value |= 1 << 3 # Enable ASM_DD_RULES
48+
value |= 1 << 4 # Enable ASM_EXCLUSIONS
49+
50+
if sys.version_info.major < 3:
51+
bytes_res = to_bytes_py2(value, (value.bit_length() + 7) // 8, "big")
52+
# "type: ignore" because mypy does not notice this is for Python2 b64encode
53+
result = str(base64.b64encode(bytes_res)) # type: ignore
54+
else:
55+
result = str(base64.b64encode(value.to_bytes((value.bit_length() + 7) // 8, "big")), encoding="utf-8")
5356

5457
return result
5558

tests/appsec/test_remoteconfiguration.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,21 @@ def test_rc_activation_states_off(tracer, appsec_enabled, rc_value, remote_confi
104104

105105

106106
@pytest.mark.parametrize(
107-
"rc_enabled, capability",
107+
"rc_enabled, appsec_enabled, capability",
108108
[
109-
("true", "Bg=="),
110-
("false", ""),
109+
("true", "true", "HA=="),
110+
("false", "true", "HA=="),
111+
("true", "false", "HA=="),
112+
("false", "false", ""),
113+
("true", "", "Hg=="),
114+
("false", "", ""),
111115
],
112116
)
113-
def test_rc_capabilities(rc_enabled, capability):
114-
with override_env({"DD_REMOTE_CONFIGURATION_ENABLED": rc_enabled}):
117+
def test_rc_capabilities(rc_enabled, appsec_enabled, capability):
118+
env = {"DD_REMOTE_CONFIGURATION_ENABLED": rc_enabled}
119+
if appsec_enabled:
120+
env[APPSEC_ENV] = appsec_enabled
121+
with override_env(env):
115122
assert _appsec_rc_capabilities() == capability
116123

117124

0 commit comments

Comments
 (0)