Ошибка ora 24247 network access denied by access control list acl

There’re two error patterns of ORA-24247 in this post.

  1. Resolve or Connect Privilege
  2. Debug Mode in SQL Developer

Resolve or Connect Privilege

For 10g database users, there could be no issues to communicate with external network using public UTL_INADDR synonym to resolve hostname. But for 11g database users, there is a problem to use UTL_INADDR, the synonym is still public, but you may have no «right» to communicate with outside world.

Let’s see a case in 10g database, UTL_INADDR is a public synonym.

$ sqlplus / as sysdba
SQL> SELECT owner, object_type, status FROM dba_objects WHERE object_name='UTL_INADDR';

OWNER                          OBJECT_TYPE         STATUS
------------------------------ ------------------- -------
SYS                            PACKAGE BODY        VALID
SYS                            PACKAGE             VALID
PUBLIC                         SYNONYM             VALID

An user HR in 10g database can resolve the hostname as following.

$ sqlplus hr/hr
SQL> select UTL_INADDR.get_host_name() from dual;

UTL_INADDR.GET_HOST_NAME()
--------------------------------------------------------------------------------
primary01.example.com

Since 11g database introduces Access Control List (ACL) to control the limited network resource and prevent security leaks, there is no more open like 10g was. Hence, in 11g database, it won’t work.

$ sqlplus hr/hr
SQL> select UTL_INADDR.get_host_name() from dual;
select UTL_INADDR.get_host_name() from dual
       *
ERROR at line 1:
ORA-24247: network access denied by access control list (ACL)
ORA-06512: at "SYS.UTL_INADDR", line 4
ORA-06512: at "SYS.UTL_INADDR", line 35
ORA-06512: at line 1

ORA-24247 means that the user should have the right network privilege in Access Control List (ACL) to resolve hostname or connect to any external servers.

There are two basic privileges in ACL to allow users to communicate with external network, one is resolve, which has the ability to resolve hostname, domain name and IP address; the other is connect, which has the ability to act as a client to connect an external host through network protocols, i.e. SMTP.

Solution to ORA-24247

If this is the first time that a user ask for specific network function, DBA must creates an ACL first. There’re 3 steps to solve our problem.

Create ACL

Create an ACL: In this case, we create an ACL with a initial user HR, and the privilege is resolve.

BEGIN
  DBMS_NETWORK_ACL_ADMIN.CREATE_ACL (
  acl => 'Connect_Access.xml',
  description => 'Connect Network',
  principal => 'HR',
  is_grant => TRUE,
  privilege => 'resolve',
  start_date => NULL,
  end_date => NULL);
END;
/

Please note that, principal is the username who initially asked for the privilege, and it must be in upper case.

The ACL document in XML format looks like a local file, but it stores as a CLOB in the database. Beside, you can customize the file name to meet your requirement.

Assign ACL

Assign the ACL to a specific network: We open the widest scope ‘*’ to users.

BEGIN
  DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL ( acl => 'Connect_Access.xml',
  host => '*',
  lower_port => NULL,
  upper_port => NULL);
END;
/

If there is any other user asks for a privilege to connect, you can add a privilege to the ACL for this user.

Add Privilege

Add another user to this ACL: We give user SH a privilege of connect.

BEGIN
  DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE (
  acl => 'Connect_Access.xml',
  principal => 'SH',
  is_grant => TRUE,
  privilege => 'connect',
  position => NULL,
  start_date => NULL,
  end_date => NULL);
END;
/

After creating the ACL, let’s make sure the setting matched our expectation.

$ sqlplus / as sysdba
SQL> column acl format a30;
SQL> SELECT acl FROM DBA_NETWORK_ACLS;

ACL
------------------------------
/sys/acls/Connect_Access.xml

SQL> column principal format a5;
SQL> column privilege format a10;
SQL> SELECT acl, principal, privilege FROM DBA_NETWORK_ACL_PRIVILEGES;

ACL                            PRINC PRIVILEGE
------------------------------ ----- ----------
/sys/acls/Connect_Access.xml   HR    resolve
/sys/acls/Connect_Access.xml   SH    connect

More Tests on ACL

The above result is correct, so we can test the privileges.

  1. Test the privilege resolve of user HR.
  2. SQL> select UTL_INADDR.get_host_name() from dual;

    UTL_INADDR.GET_HOST_NAME()
    --------------------------------------------------------------------------------
    primary01.example.com

    It succeed to resolve a hostname.

  3. Test the privilege connect of user SH.
  4. Here we use an anonymous PL/SQL block to test the function, which is an example of using UTL_SMTP provided by Oracle 11g Documentation, we just modified it for testing purpose.

    DECLARE
      c UTL_SMTP.CONNECTION;

      PROCEDURE send_header(name IN VARCHAR2, header IN VARCHAR2) AS
      BEGIN
        UTL_SMTP.WRITE_DATA(c, name || ': ' || header || UTL_TCP.CRLF);
      END;

    BEGIN
      c := UTL_SMTP.OPEN_CONNECTION('ms1.hinet.net');
      UTL_SMTP.HELO(c, 'foo.com');
      UTL_SMTP.MAIL(c, 'edchenlogic@gmail.com');
      UTL_SMTP.RCPT(c, 'edchenlogic@gmail.com');
      UTL_SMTP.OPEN_DATA(c);
      send_header('From',    '"From Blog Tester" <edchenlogic@gmail.com>');
      send_header('To',      '"To Blog Tester" <edchenlogic@gmail.com>');
      send_header('Subject', 'This is a test for network connection');
      UTL_SMTP.WRITE_DATA(c, UTL_TCP.CRLF || 'If you receive this mail, you are able to connect external network.');
      UTL_SMTP.CLOSE_DATA(c);
      UTL_SMTP.QUIT(c);
    EXCEPTION
      WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
        BEGIN
          UTL_SMTP.QUIT(c);
        EXCEPTION
          WHEN UTL_SMTP.TRANSIENT_ERROR OR UTL_SMTP.PERMANENT_ERROR THEN
            NULL; -- When the SMTP server is down or unavailable, we don't have
                  -- a connection to the server. The QUIT call will raise an
                  -- exception that we can ignore.
        END;
        raise_application_error(-20000,
          'Failed to send mail due to the following error: ' || sqlerrm);
    END;
    /

    It works, and the testing email as:

    ACL Connect Test

    ACL Connect Test

Since HR has only resolve privilege, he will get errors as following if he execute the same block of code.

ORA-24247: network access denied by access control list (ACL)
ORA-06512: at "SYS.UTL_TCP", line 17
ORA-06512: at "SYS.UTL_TCP", line 246
ORA-06512: at "SYS.UTL_SMTP", line 127
ORA-06512: at "SYS.UTL_SMTP", line 150
ORA-06512: at line 10

As we can see, HR is prohibited to connect the network, which means ACL is taking effect.

Debug Mode in SQL Developer

To debug a programming unit of PL/SQL in SQL Developer, you can click on the bug icon to enable the function. But later on, you might see ORA-24247.

Oracle SQL Developer - Debug Icon

Oracle SQL Developer — Debug Icon

Unfortunately, most developers met a stack of errors like this:

SQL Developer - ORA-24247 when using DBMS_DEBUG_JDWP

SQL Developer — ORA-24247 when using DBMS_DEBUG_JDWP

Connecting to the database ORCLPDB.
Executing PL/SQL: CALL DBMS_DEBUG_JDWP.CONNECT_TCP('192.168.30.128', '49216')

ORA-24247: network access denied by access control list (ACL)
ORA-06512: AT "SYS.DBMS_DEBUG_JDWP", line 68
ORA-06512: AT line 1
Process exited.
Disconnecting from the database ORCLPDB.

ORA-24247 means that the default debug method in SQL developer is to use DBMS_DEBUG_JDWP in order to communicate with the database, which requires users have the permission to connect back to client’s tool through network.

Solution to ORA-24247

Although we can try to add the client’s IP address or hostname to the white list of ACL in the database, the solution usually fails.

To avoid ACL problem, we can switch the debug method to the normal DBMS_DEBUG in preferences of SQL developer.

Go to Preferences

SQL Developer - Preferences

SQL Developer — Preferences

Enable DBMS_DEBUG

SQL Developer - Enable DBMS_DEBUG

SQL Developer — Enable DBMS_DEBUG

Next, I guess you might be interested in changing the user interface language of SQL developer to increase your programming productivity.

Before Oracle 11g access to network services was controlled by granting privileges on packages such as UTL_HTTP, UTL_TCP, UTL_SMTP, and UTL_MAIL. After 11.1 Oracle introduced Application Control Lists (ACL) as part of their Application Security and has now added Application Control Entry (ACE).

If you run into the ORA-24247: network access denied by access control list (ACL) error you can use one of the following methods to resolve the error.

  1. The best solution to the ORA-24247 error is to create an ACE using the DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE procedure to grant access control privileges to a user. According to Oracle documentation, the procedure will append an access control entry with specified privilege to the ACL for the given host. If the ACL does not exist it will create it for you. The syntax for the procedure is listed below.
BEGIN
 DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE (
  host         => 'host_name', 
  lower_port   => null|port_number,
  upper_port   => null|port_number,
  ace          => ace_definition); 
END;
  • host: can be either the ip address or the hostname. You can also use a wildcard for a domain or an IP subnet.
    host => ‘mailhost.com’
    host => ‘*.domain.com’
  • lower_port and upper_port: these values are used to set the lower and upper port range. This is only used for the connect privilege and can be omitted for the resolve privilege. If set to null then there are no port restrictions.
    lower_port => 80
    upper_port => 3999
  • ace: You define the ACE by using the XS$ACE_TYPE constant with the following specifications.
    • privilege_list: this can be one or more of the following, http, http_proxy, smtp, resolve, connect, jdwp. Enclose each privilege with single quotes and separate each with a comma.
    • principal_name: enter either a database user or role.
    • principal_type: enter xs_acl_ptype_db for a database user or role.

In this example, the user Scott is being granted network access to send SMTP to a host, mailhost.com, through the UTL_SMTP and UTL_MAIL packages.

BEGIN
DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE
(
HOST => 'mailhost.com',
LOWER_PORT => NULL,
UPPER_PORT => NULL,
ACE => XS$ACE_TYPE(PRIVILEGE_LIST => xs$name_list('smtp'),
    			     PRINCIPAL_NAME => 'Scott',
    		     PRINCIPAL_TYPE => xs_acl.ptype_db
   		   )
);
END;
/
  1. The second method for resolving the ORA-24247 error is to grant the user requesting network access the XDBADMIN role.
    SQL> grant XDBADMIN to Scott;

This will grant an extra privilege to the Oracle user and is not recommended.

Recently we have switched from Oracle 10g to 11g, and only now I noticed that my mailing function does not work, I now get an error:

ORA-24247: network access denied by access control list (ACL)

So I did a bit of googling and was able to figure out that a new feature in Oracle 11g is now restricting users from using certain packages including utl_smtp. Because I am looking for a quick solution I did not read Oracle documentation, but instead I went looking for easier solutions and came across this tutorial:

https://www.pythian.com/blog/setting-up-network-acls-in-oracle-11g-for-dummies/

I messed around with it a little bit, but because I did not know any better I think I added two seperate configuration .xml files. So first part of my question is — HOW DO I REMOVE IT?

Second question is:

After adding some grants to my user I try to test to see if it worked, but I soon realised it did not:

  SELECT DECODE(
         DBMS_NETWORK_ACL_ADMIN.check_privilege('netacl.xml', 'TEST1', 'connect'),
         1, 'GRANTED', 0, 'DENIED', NULL) privilege 
FROM dual;

Returns:

PRIVILE
-------
DENIED

WHY?(THIS HAS BEEN SORTED)

Third part of the question — after reading it was denied I try to fix it like:

BEGIN
  DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE('netacl.xml' ,'TEST1', TRUE, 'connect');
END;

But that gives me an error:

Ora19279 - XQuery dynamic type mismatch.....(more text meaning nothing to me).

WHY?(I FIGURED OUT, THAT ERROR HAPPENS WHEN YOU GRANT SAME PERMISSION TO SAME USER SECOND TIME)

UPDATE

I have followed the suggested answer by kevinsky below and have learned quite a bit in the process, however I still have a problem. I still get the ORA-24247: network access denied by access control list (ACL). Because I did everything else as suggested, I am starting to think that the problem could be that first configuration file which I added, but cannot remove now because I cannot remember its name. If anyone can help me I would appreciate that very much.

RESULTS OF(I was trying out a few different things so):

select * from dba_network_acls;

Returns

*                              | 25 | 25 | /sys/acls/utl_smtp.xml| ACLID...
myservername.com               | 25 | 25 | /sys/acls/utl_smtp.xml| ACLID...
myDBName                       | 25 | 25 | /sys/acls/utl_smtp.xml| ACLID...
mailServerDomainName           | 25 | 25 | /sys/acls/utl_smtp.xml| ACLID...
mailserver.myDomain.local      | 25 | 25 | /sys/acls/utl_smtp.xml| ACLID...

This manuel describes the solution ORA-24247: network access denied by access control list (ACL).

for the ACL’ss offers oracle more fine-grained access control for users who have access to external resources.
The packages UTL_MAIL , UTL_SMTP , UTL_HTTP , UTL_TCP etc. provide the ability to communicate to the outside world. When there are rights, data can be created from the database connection to all hosts. This can be seen as a security hole because there is no login is required . Since Oracle 11g , the Access Control List is introduced. You can not only control who has access to these packages, but you can also determine which resources they may comminceren .
For example, when a user is allowed to send emails through UTL_MAIL , you can also determine which server it should gebeuren.Ik UTL_MAIL will use the package as an example When a user does not have permission to email appears the error message:

ORA-24247: network access denied by access control list (ACL).

SQL> connect scott/tiger Connected.

begin

  utl_mail.send(

  sender => ‘scott@tiger.com’

  recipients => ‘john@doe.org’

  message=> ‘ Hello World’

  );

ERROR at line 1: ORA-24247: network access denied by access control list (ACL) ORA-06512: at “SYS.UTL_MAIL”, line 654 ORA-06512: at “SYS.UTL_MAIL”, line 671 ORA-06512: at line 1

This is because the user SCOTT has no rights to connect to the mail or SMTP servers. The user must be added to the ACL

Create ACL and privilege

The ACL is created as a file and manages the process of handing out rights and privileges. First we are going to create an ACL as SYS or another user with the right to execute DBMS_NETWORK_ACL_ADMIN . This file hold the rights to . You can add as many rights to this file.

begin

dbms_network_acl_admin.create_acl (

acl         => ‘utl_mail.xml’,

description => ‘Allow mail to be send’,

principal   => ‘SCOTT’,

is_grant    => TRUE,

privilege   => ‘connect’

);

commit;

end;

Add Privilege

Now that the ACL is created you can add more as the privilege to ‘ resolve ‘ privilege .

begin

dbms_network_acl_admin.add_privilege (

acl       => ‘utl_mail.xml’,

principal => ‘SCOTT’,

is_grant  => TRUE,

privilege => ‘resolve’

);

commit;

end;

Grant ACL

The user SCOTT is granted connect and resolve , but there is not yet indicated to what resources he can connect.

begin

dbms_network_acl_admin.assign_acl(

acl  => ‘utl_mail.xml’,

host => ‘smtp server host name or address’

);

commit;

end;

Test

SQL> connect scott/tiger

Connected.

begin

utl_mail.send(

sender     => ‘scott@tiger.com’,

recipients => ‘john@doe.org’,

message    => ‘Hello World’

);

commit;

end;

PL/SQL procedure successfully completed.

Connection to websites and TCP ports

With the ACL , you can set up TCP ranges start and end dates.

SQL> select utl_http.request(‘http://www.tiger.com’) from dual;

select utl_http.request(‘http://www.tiger.com’) from dual

*

ERROR at line 1:

ORA29273: HTTP request failed

ORA06512: at «SYS.UTL_HTTP», line 1722

ORA24247: network access denied by access control list (ACL)

ORA06512: at line 1

Create ACL, add privileges and TCP ports

Excecute as SYS

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

begin

dbms_network_acl_admin.create_acl (

acl         => ‘utl_http.xml’,

description => ‘HTTP Access’,

principal   => ‘SCOTT’,

is_grant    => TRUE,

privilege   => ‘connect’,

start_date  => null,

end_date    => null

);

dbms_network_acl_admin.add_privilege (

acl        => ‘utl_http.xml’,

principal  => ‘SCOTT’,

is_grant   => TRUE,

privilege  => ‘resolve’,

start_date => null,

end_date   => null

);

dbms_network_acl_admin.assign_acl (

acl        => ‘utl_http.xml’,

host       => ‘www.tiger.com’,

lower_port => 80,

upper_port => 80

);

commit;

end;

In the hosts parameter dbms_network_acl_admin.assign_acl, can you can al so add wild cards ‘*.tiger.com’ or even ‘*’.

Execute as SCOTT:

SQL> select utl_http.request(‘http://www.tiger.com’) from dual;

UTL_HTTP.REQUEST(‘HTTP://WWW.TIGER.COM’)

[result here]

Now try to connect to the same URL but with a different port .

SQL> select utl_http.request(‘http://www.tiger.com:1234’) from dual;

select utl_http.request(‘http://www.tiger.com:1234’) from dual

*

ERROR at line 1:

ORA29273: HTTP request failed

ORA06512: at «SYS.UTL_HTTP», line 1722

ORA24247: network access denied by access control list (ACL)

ORA06512: at line 1

dba_network_acls

You can by carrying out the following view the ACL and privileges by reacting a query loose on the dba_network_acls .

select host, lower_port, upper_port, acl

from dba_network_acls

where ACL=‘/sys/acls/’utl_http.xml;

Remove ACL and priviliges

Execute asSYS:

Unassign ACL

begin

dbms_network_acl_admin.unassign_acl(

acl        => ‘utl_http.xml’,

host       => ‘www.tiger.com’,

   lower_port => 80,

   upper_port => 80

  );

end;

Remove Privilege

begin

dbms_network_acl_admin.delete_privilege(

    ‘utl_http.xml’, ‘SCOTT’, NULL, ‘connect’

  );

end;

Drop ACL

begin

dbms_network_acl_admin.drop_acl(

    ‘utl_http.xml’

  );

end;

Activate UTL_MAIL

SQL> @?/rdbms/admin/utlmail.sql

SQL> @?/rdbms/admin/prvtmail.plb

SQL> alter system set smtp_out_server = ‘<smtp host>’ scope=spfile;

SQL> shutdown immediate

SQL> startup

Please let me know if this manual ‘Oracle 11g Acces Control List and ORA-24247’ was usefull to you. If there are  errors or you have suggestions regarding this manual, please let me know. No rights can be derived from this manual

Regards,

Maarten

Asked
11 years, 2 months ago

Viewed
10k times

I seem to be getting the above error, and I tried sending a mail over the intranet as well, but of no use.
Does the above error message mean that my mail program is correct, and the problem is with the restriction imposed on an user, by the database administrator?

Barbaros Özhan's user avatar

asked Apr 11, 2012 at 14:11

user980411's user avatar

Taken from http://www.dba-oracle.com/t_ora_24247_network_access_denied_by_access_control_list_tips.htm:

ORA-24247: network access denied by access control list (ACL)

Cause: No access control list (ACL) has been assigned to the target
host or the privilege necessary to access the target host has not been
granted to the user in the access control list.

Action: Ensure that an access control list (ACL) has been assigned to
the target host and the privilege necessary to access the target host
has been granted to the user.

Your application will encounter an ORA-24247 error if it relies on one
of the network packages and no proper ACL has been created. For the
use of the following packages it is mandatory to have an ACL for the
application user in place in 11g:

UTL_TCP

UTL_SMTP

UTL_MAIL

UTL_HTTP

UTL_INADDR

Also read the following post by Ian Hoogeboom

answered Apr 11, 2012 at 14:15

Dor Cohen's user avatar

Dor CohenDor Cohen

16.7k23 gold badges92 silver badges160 bronze badges

1

  • Ошибка ora 12519 tns no appropriate service handler found
  • Ошибка ora 12518 tns listener could not hand off client connection
  • Ошибка ora 12514 tns listener does not currently know of service requested in connect descriptor
  • Ошибка ora 12154 tns could not resolve the connect identifier specified
  • Ошибка or gsteh 06