Skip to content

Commit

Permalink
Enable container port, not the host port
Browse files Browse the repository at this point in the history
Udica should allow container port in generated policy not the host port.

Resolves: #62
  • Loading branch information
wrabcak committed Aug 13, 2020
1 parent 00b166f commit 3678e2f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions udica/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ def get_ports(self, data):
ports = []
for key, value in data[0]["NetworkSettings"]["Ports"].items():
container_port = str(key).split("/")
host_port = value[0]["HostPort"]
new_port = {"hostPort": int(host_port), "protocol": container_port[1]}
new_port = {
"portNumber": int(container_port[0]),
"protocol": container_port[1],
}
ports.append(new_port)
return ports

Expand Down
4 changes: 2 additions & 2 deletions udica/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ def create_policy(opts, capabilities, mounts, ports, append_rules, inspect_forma

# ports
for item in ports:
if "hostPort" in item:
if "portNumber" in item:
policy.write(
" (allow process "
+ list_ports(item["hostPort"], item["protocol"])
+ list_ports(item["portNumber"], item["protocol"])
+ " ( "
+ perms.socket[item["protocol"]]
+ " ( name_bind ))) \n"
Expand Down

0 comments on commit 3678e2f

Please sign in to comment.