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, theHOSTvalue of each ACE, and returns a number. WhenHOSTis a host name, the number is the level of its domain plus 1. WhenHOSTis a domain name such as*.example.com, the number is the level of that domain. WhenHOSTis the wildcard*, the number is 0. WhenHOSTis an IP address or subnet, the number is the count of significant address bits. When the target is not equal to or contained inHOST, the function returns NULL. A higher number means higher precedence. Replacewww.us.example.comwith the host from the failing call.- No name lookup:
CONTAINS_HOSTdoes 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 forwww.us.example.comsorts 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 theconnectrule: when one host hasconnectentries 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_PORTandUPPER_PORT(NUMBER(5)) bound the port range.PRINCIPALnames who the entry applies to, andPRINCIPAL_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_DATEandEND_DATE(TIMESTAMP(6)) show whether the entry takes effect only during a set period. PRECEDENCEis not selected: The outer list leaves the computed score out. AddPRECEDENCEto the outer column list if you want to see why one row sorts above another.
Key Points
DBA_HOST_ACLSandDBA_HOST_ACESare the views that Oracle Database 12c introduced for this job, so an 11g database has noDBA_HOST_ACESfor this script to read. The olderDBA_NETWORK_ACLSandDBA_NETWORK_ACL_PRIVILEGESviews are deprecated in 12c, and so are many subprograms inDBMS_NETWORK_ACL_ADMIN. After an upgrade to 12c or later, move scripts that read the old views to the new ones.- Only
SELECT_CATALOG_ROLEgets the SELECT privilege onDBA_HOST_ACES. EXECUTE onDBMS_NETWORK_ACL_UTILITYis granted toPUBLIC. Any account can callCONTAINS_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_DATEandEND_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:
connectopensUTL_TCP,UTL_SMTP,UTL_MAIL,UTL_HTTP,DBMS_LDAPand theHttpUriTypetype.resolvelimits access toUTL_INADDR.httplimits access toUTL_HTTPand theHttpUriTypetype.smtplimits access toUTL_SMTPandUTL_MAIL.http_proxyis needed together withhttpwhen HTTP access goes through a proxy. Append that entry to the proxy host, not the destination: through a proxy,UTL_HTTPneeds 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_TCPorUTL_INADDRfails 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
HOSTis*match every target.CONTAINS_HOSTscores them 0, so they appear at the bottom of the result. - A user checked
USER_HOST_ACESand 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
- DBA_HOST_ACES, Oracle Database 19c Reference - The view's purpose and the type and meaning of every column the script selects.
- Checking Privilege Assignments That Affect User Access to Network Hosts, Oracle Database 19c Security Guide - The source of the script (Example 10-8, "Administrator Checking User Network Access Control Permissions"), plus the rules on USER_HOST_ACES filtering out entries that do not apply to the user, time windows and separate port configurations.
- Data Dictionary Views for Access Control Lists, Oracle Database 19c Security Guide - Who can select from DBA_HOST_ACES and what DBA_HOST_ACLS shows.
- DBMS_NETWORK_ACL_UTILITY, Oracle Database 19c PL/SQL Packages and Types Reference - CONTAINS_HOST return values for host, domain, subnet and wildcard, precedence, IPv4-mapped addresses and the PUBLIC grant.
- DBMS_NETWORK_ACL_ADMIN, Oracle Database 19c PL/SQL Packages and Types Reference - Host and port precedence, port overlap, the resolve limit, APPEND_HOST_ACE and REMOVE_HOST_ACE behavior, and default EXECUTE grants.
- UTL_HTTP, Oracle Database 19c PL/SQL Packages and Types Reference - The connect privilege on the remote web server host or, through a proxy, on the proxy host.
- Configure ACEs for a User or Role to Use DBMS_CLOUD, Oracle Database 19c Utilities - An example ACE with
httpandhttp_proxyappended to the proxy host. - DBA_HOST_ACLS, Oracle Database 19c Reference - The ACLID and ACL_OWNER columns.
- USER_HOST_ACES, Oracle Database 19c Reference - What the current-user view describes.
- ORA-24247, Oracle Database Error Help - The two causes of the network access error.
- Fine-Grained Access to Network Services Enhancements in Oracle Database 12c Release 1, oracle-base.com - The 12c view changes, privilege names and scope, the default deny, multitenant ACEs and the 10g upgrade issue.
Posts in this series
- How to Block a User in Oracle Database (ACCOUNT LOCK)
- Oracle dba_users: List All User Account Information
- dba_role_privs: List Oracle Roles Granted to a User
- dba_roles PASSWORD_REQUIRED: Query Oracle Role Definitions
- Oracle Table Privileges Granted to a Role via role_tab_privs
- Check Network ACL Privileges for a Host with DBA_HOST_ACES