Check Network ACL Privileges for a Host with DBA_HOST_ACES

Check Network ACL Privileges for a Host with DBA_HOST_ACES

Purpose

A UTL_HTTP call fails with ORA-24247: network access denied by access control list (ACL). This error has two causes. Either no access control list (ACL) is assigned to the target host, or the ACL does not grant the user the privilege needed to reach that host. Oracle denies access to external network services by default, so a call that no entry allows will fail.

DBA_HOST_ACES lists the access control entries (ACEs) defined in host ACLs. An ACE is one row that grants or denies a privilege to a principal (a user or a role) for a host. Network ACLs control the UTL_TCP, UTL_HTTP, UTL_SMTP and UTL_INADDR packages. The script takes one host name and returns every ACE that covers it. The rows come back in precedence order: the most specific host first, entries with a port range before entries without one, and then the order of the entries inside the list.

The script needs Oracle Database 12c or later, because DBA_HOST_ACES is one of the views 12c added. Run it when a network call fails, before you add a new ACE, and after you upgrade a database that calls external services from 10g to 12c.

Code

 1SELECT HOST, LOWER_PORT, UPPER_PORT, ACE_ORDER, PRINCIPAL, PRINCIPAL_TYPE,
 2      GRANT_TYPE, INVERTED_PRINCIPAL, PRIVILEGE,
 3      START_DATE, END_DATE
 4  FROM (SELECT ACES.*,
 5DBMS_NETWORK_ACL_UTILITY.CONTAINS_HOST('www.us.example.com',
 6                                       HOST) PRECEDENCE
 7          FROM DBA_HOST_ACES ACES)
 8 WHERE PRECEDENCE IS NOT NULL
 9 ORDER BY PRECEDENCE DESC,
10          LOWER_PORT NULLS LAST,
11          UPPER_PORT NULLS LAST,
12          ACE_ORDER;

Code Breakdown

  • SELECT ACES.* ... FROM DBA_HOST_ACES ACES: The inner query reads every ACE in every host ACL and keeps all of its columns. At this point nothing is filtered. A wildcard entry, a domain entry and an entry for an unrelated host all pass through.
  • DBMS_NETWORK_ACL_UTILITY.CONTAINS_HOST('www.us.example.com', HOST) PRECEDENCE: This function checks whether the target host is equal to, or contained in, the HOST value of each ACE, and returns a number. When HOST is a host name, the number is the level of its domain plus 1. When HOST is a domain name such as *.example.com, the number is the level of that domain. When HOST is the wildcard *, the number is 0. When HOST is an IP address or subnet, the number is the count of significant address bits. When the target is not equal to or contained in HOST, the function returns NULL. A higher number means higher precedence. Replace www.us.example.com with the host from the failing call.
  • No name lookup: CONTAINS_HOST does not perform domain name resolution. It compares the strings and addresses you give it. If an ACE names a host and you pass that host's IP address, the ACE does not match. An IPv4-mapped IPv6 address counts as equal to the IPv4 address it represents.
  • WHERE PRECEDENCE IS NOT NULL: This drops every ACE that does not cover the target host. Only entries for the host itself, its parent domains, a subnet that holds it, or * remain.
  • ORDER BY PRECEDENCE DESC: The most specific match comes first. This matches the rule that a host's ACL takes precedence over its domains' ACLs. An entry for www.us.example.com sorts above an entry for *.example.com, and an entry for * sorts last.
  • LOWER_PORT NULLS LAST, UPPER_PORT NULLS LAST: Inside one precedence level, entries with a port range come before entries with no port. This follows the connect rule: when one host has connect entries both with and without a port range, the one with a port range takes precedence. When an ACE is created with a NULL upper port, Oracle uses the lower port as the upper bound.
  • ACE_ORDER: The last sort key is the order number of the entry (NUMBER, NOT NULL). It keeps rows from the same list in the order they were defined.
  • Columns in the outer list: HOST (VARCHAR2(1000)) is the network host. LOWER_PORT and UPPER_PORT (NUMBER(5)) bound the port range. PRINCIPAL names who the entry applies to, and PRINCIPAL_TYPE (VARCHAR2(16)) gives the type of that principal. GRANT_TYPE (VARCHAR2(5)) shows whether the entry grants or denies the privilege. INVERTED_PRINCIPAL (VARCHAR2(3)) shows whether the principal is inverted. PRIVILEGE (VARCHAR2(128)) is the privilege name. START_DATE and END_DATE (TIMESTAMP(6)) show whether the entry takes effect only during a set period.
  • PRECEDENCE is not selected: The outer list leaves the computed score out. Add PRECEDENCE to the outer column list if you want to see why one row sorts above another.

Key Points

  • DBA_HOST_ACLS and DBA_HOST_ACES are the views that Oracle Database 12c introduced for this job, so an 11g database has no DBA_HOST_ACES for this script to read. The older DBA_NETWORK_ACLS and DBA_NETWORK_ACL_PRIVILEGES views are deprecated in 12c, and so are many subprograms in DBMS_NETWORK_ACL_ADMIN. After an upgrade to 12c or later, move scripts that read the old views to the new ones.
  • Only SELECT_CATALOG_ROLE gets the SELECT privilege on DBA_HOST_ACES. EXECUTE on DBMS_NETWORK_ACL_UTILITY is granted to PUBLIC. Any account can call CONTAINS_HOST, but only an account with catalog access can read the view.
  • The output is not a final yes or no for a user. To decide whether a user has a privilege right now, you still combine the current time with START_DATE and END_DATE, the roles the user holds, and the order of the entries. For each ACL, the result for one user is one of three: it grants, it denies, or it does not apply.
  • In a multitenant database, ACEs can be created at the CDB level or the PDB level. Check which container your session is in before you read the result.

Insights and Best Practices

Read the Result from the Top

The script takes no port number. A row for ports 3000-3999 therefore sorts above a row with no port, even when the failing call uses port 80. Read from the top and skip every row whose LOWER_PORT to UPPER_PORT range does not include the port the call uses. Among the rows that remain, host entries beat domain entries, and for connect, a port-range entry beats an entry with no port. Start your diagnosis at the first remaining row that matches the user, or a role the user holds, and the privilege.

To grant a host on port 80 and deny it on ports 3000-3999, you need one access control configuration for port 80 and a separate one for 3000-3999. Port ranges on one host cannot overlap with other port ranges on that host. Before you add a range, run the script and look at the LOWER_PORT and UPPER_PORT values already present.

Grant the Narrowest Privilege

Since 12c, an ACE can be limited to specific PL/SQL APIs through the privilege name:

  • connect opens UTL_TCP, UTL_SMTP, UTL_MAIL, UTL_HTTP, DBMS_LDAP and the HttpUriType type.
  • resolve limits access to UTL_INADDR.
  • http limits access to UTL_HTTP and the HttpUriType type.
  • smtp limits access to UTL_SMTP and UTL_MAIL.
  • http_proxy is needed together with http when HTTP access goes through a proxy. Append that entry to the proxy host, not the destination: through a proxy, UTL_HTTP needs its privileges on the proxy host.

A user who only sends mail needs smtp, not connect. Restrict the port too. If the code only needs HTTP on port 80, name port 80 instead of opening all ports on the server. An ACE with the resolve privilege can only be added to a host ACL that has no port range.

Pair the Result with DBA_HOST_ACLS

DBA_HOST_ACES shows the entries. DBA_HOST_ACLS shows which access control list is assigned to each host. It carries ACLID (RAW(8), the object ID of the list) and ACL_OWNER (VARCHAR2(128)). When the script returns no rows for a host, DBA_HOST_ACLS tells you whether the host has a list at all. That separates the two causes of ORA-24247.

Let Users Check Their Own Access

USER_HOST_ACES describes the status of ACEs for the current user to reach network hosts through the PL/SQL network utility packages. The view is PUBLIC, so every user can query it. It lists only the entries that grant or deny the current user, and filters out the entries that do not apply to that user. A domain or * entry that grants or denies the user does appear. A developer can use it to check their own access without catalog privileges. To see every entry on a host, including those for other users and roles, a DBA still needs to run this script.

Change Entries with Care

EXECUTE on DBMS_NETWORK_ACL_ADMIN goes to the DBA role and to EXECUTE_CATALOG_ROLE by default. Keep that list short, because this package controls who can open network connections from the database.

When you add an entry with APPEND_HOST_ACE:

  • Oracle creates a host ACL for the host if it has none yet.
  • A privilege that the matching ACE already holds is not added again.
  • If the ACL is shared with another host or a wallet, Oracle copies the ACL before it changes it.

After any change, rerun the script and check DBA_HOST_ACLS to see which list each host now uses.

When you remove an entry with REMOVE_HOST_ACE, the remove_empty_acl parameter decides whether an unused host ACL is removed. It defaults to FALSE, so an empty list stays assigned to the host unless you pass TRUE. The 12c release deprecated the older ACL subprograms in the same package. Use the host ACE calls in new scripts.

When to Run This

  • A PL/SQL call through UTL_HTTP, UTL_SMTP, UTL_TCP or UTL_INADDR fails with ORA-24247.
  • You upgraded a database that calls external network services from 10g to 12c, and its network calls now fail.
  • You plan to add an ACE with a port range and need to know which ranges already exist on that host.
  • During a security review, you need to list the principals that can reach any host. Rows where HOST is * match every target. CONTAINS_HOST scores them 0, so they appear at the bottom of the result.
  • A user checked USER_HOST_ACES and found no entry for the host, so no entry grants or denies that user directly. Run this script to see every entry on the host and its domains, including those for other users and roles.

Troubleshooting Common Issues

The script returns no rows. No ACE covers the host string you passed. Check the spelling first. Host and domain names in ACL entries are case-insensitive, so a difference in case is not the cause. Then check whether the calling code uses an IP address while the ACE names a host, or the other way round. CONTAINS_HOST does no name lookup, so the two forms never match each other. If neither form returns rows, query DBA_HOST_ACLS for the host. No ACL there means no ACL is assigned, the first cause of ORA-24247. An ACL there with no entries means the list grants nothing, the second cause. An empty list can remain after REMOVE_HOST_ACE runs with remove_empty_acl left at FALSE.

Rows come back, but the call still fails. Compare the port the call uses with LOWER_PORT and UPPER_PORT on each row. A row whose range does not include that port does not apply to the call, even when it sorts first. Then read the remaining rows for the failing user and for every role that user holds. Look for a row where GRANT_TYPE shows a deny above the grant you expected. Compare START_DATE and END_DATE with the current time: an entry that has expired or has not started yet does not apply. Check that PRIVILEGE matches the package in use. A smtp grant does not cover UTL_HTTP. If the call goes through a proxy, the user needs connect or http together with http_proxy on the proxy host, not only on the destination.

The query fails for a non-DBA account. Only SELECT_CATALOG_ROLE gets SELECT on DBA_HOST_ACES. Grant that role to the support account, or have the user query USER_HOST_ACES, keeping in mind that it lists only entries that grant or deny that user, so it cannot show entries for other users or roles.

Adding an entry fails. A new port range cannot overlap an existing range on the same host, so compare it with the ranges the script lists. A resolve entry fails when it targets a host ACL with a port range. Add it to the host with no port range instead.

References

Posts in this series