Skip to content

Commit 4e17d67

Browse files
committed
Add prefix to variables imported from the container configuration
Unprefixed variables won't be processed in offline mode
1 parent f865cb4 commit 4e17d67

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/OVAL/probes/independent/environmentvariable58_probe.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "environmentvariable58_probe.h"
6060

6161
#define BUFFER_SIZE 256
62+
#define VAR_OFFLINE_PREFIX "OSCAP_OFFLINE_"
6263

6364
extern char **environ;
6465

@@ -157,16 +158,28 @@ static int read_environment(SEXP_t *pid_ent, SEXP_t *name_ent, probe_ctx *ctx)
157158
continue;
158159
}
159160

160-
env_name_size = eq_char - buffer;
161-
env_name = SEXP_string_new(buffer, env_name_size);
161+
env_name_size = eq_char - buffer;
162+
if (ctx->offline_mode == PROBE_OFFLINE_OWN) {
163+
// We are not processing unprefixed (i.e. originated from the host) variables in offline mode
164+
if (memmem(buffer, env_name_size, VAR_OFFLINE_PREFIX, strlen(VAR_OFFLINE_PREFIX)) != buffer
165+
|| strlen(VAR_OFFLINE_PREFIX) >= env_name_size) {
166+
buffer_used -= null_char + 1 - buffer;
167+
memmove(buffer, null_char + 1, buffer_used);
168+
continue;
169+
}
170+
env_name = SEXP_string_new(buffer + strlen(VAR_OFFLINE_PREFIX), env_name_size - strlen(VAR_OFFLINE_PREFIX));
171+
} else {
172+
env_name = SEXP_string_new(buffer, env_name_size);
173+
}
162174
env_value = SEXP_string_newf("%s", buffer + env_name_size + 1);
175+
163176
if (probe_entobj_cmp(name_ent, env_name) == OVAL_RESULT_TRUE) {
164177
item = probe_item_create(
165178
OVAL_INDEPENDENT_ENVIRONMENT_VARIABLE58, NULL,
166179
"pid", OVAL_DATATYPE_INTEGER, (int64_t)pid,
167180
"name", OVAL_DATATYPE_SEXP, env_name,
168181
"value", OVAL_DATATYPE_SEXP, env_value,
169-
NULL);
182+
NULL);
170183
probe_item_collect(ctx, item);
171184
err = 0;
172185
}

utils/oscap-podman

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fi
8080
DIR=$(podman mount $ID) || die
8181

8282
for VAR in `podman inspect $ID --format '{{join .Config.Env " "}}'`; do
83-
eval "export $VAR"
83+
eval "export OSCAP_OFFLINE_$VAR"
8484
done
8585

8686
export OSCAP_PROBE_ROOT="$(cd "$DIR"; pwd)"

utils/oscap_docker_python/oscap_docker_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def oscap_chroot(self, chroot_path, target, *oscap_args):
155155
os.environ["OSCAP_EVALUATION_TARGET"] = name
156156
for var in config.get("Env", []):
157157
vname, val = var.split("=", 1)
158-
os.environ[vname] = val
158+
os.environ["OSCAP_OFFLINE_"+vname] = val
159159
cmd = [self.oscap_binary] + [x for x in oscap_args]
160160
oscap_process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
161161
oscap_stdout, oscap_stderr = oscap_process.communicate()

0 commit comments

Comments
 (0)