Wednesday 13 October 2010

Access Control List (ACL) Problems when using the UTL_TCP Package for FTP in Oracle 11g

I am sure you have read this. But pay attention that it is address to:
- particular IP address or host name
- particular Oracle user

First, create an ACL:

begin
        dbms_network_acl_admin.create_acl (
                acl             => 'utlpkg.xml',
                description     => 'Normal Access',
                principal       => 'CONNECT',
                is_grant        => TRUE,
                privilege       => 'connect',
                start_date      => null,
                end_date        => null
        );
end;

Here the parameter principal => 'CONNECT' indicates that the ACL applies to the CONNECT role. You can define a user or a role here. The ACL is created as a file called utlpkg.xml. 
After the creation, you can check to make sure the ACL was added:

SELECT any_path
FROM resource_view
WHERE any_path like '/sys/acls/%.xml';

The output is: 
ANY_PATH
----------------------------------------------------------------------------
/sys/acls/ANONYMOUS/ANONYMOUS3553d2be53ca40e040a8c0680777c_acl.xml
/sys/acls/OLAP_XS_ADMIN/OLAP_XS_ADMIN3551b25f93feb8dde040a8c068075b7_acl.xml
/sys/acls/OLAP_XS_ADMIN/OLAP_XS_ADMIN3551b25f944b8dde040a8c068075b7_acl.xml
/sys/acls/OLAP_XS_ADMIN/OLAP_XS_ADMIN3551b25f948b8dde040a8c068075b7_acl.xml
/sys/acls/OLAP_XS_ADMIN/OLAP_XS_ADMIN3551b25f94cb8dde040a8c068075b7_acl.xml
/sys/acls/all_all_acl.xml
/sys/acls/all_owner_acl.xml
/sys/acls/bootstrap_acl.xml
/sys/acls/ro_all_acl.xml
/sys/acls/ro_anonymous_acl.xml
/sys/acls/utlpkg.xml

Note the last line in the output, which shows the ACL you just created. Next, add a privilege to this ACL. In this example, you are trying to limit this ACL to the user SCOTT. You can also define start and end dates. 
begin
  dbms_network_acl_admin.add_privilege ( 
  acl             => 'utlpkg.xml',
  principal       => 'SCOTT',
  is_grant       => TRUE, 
  privilege       => 'connect', 
  start_date       => null, 
  end_date       => null); 
end;

Assign hosts and other details that will be subject to this ACL: 
begin
  dbms_network_acl_admin.assign_acl (
  acl => 'utlpkg.xml',
  host => '
www.proligence.com',
  lower_port => 22,
  upper_port => 55);
end;

In this example, you are specifying that "the user SCOTT can call only the host 
www.proligence.com and only for the ports 22 through 55, and not outside it." Now, let's try it: 
SQL> grant execute on utl_http to scott
  2  /
 
Grant succeeded.
 
SQL> conn scott/tiger
Connected.
SQL> select utl_http.request('
http://www.proligence.com') from dual;
select utl_http.request('
http://www.proligence.com') from dual
       *
ERROR at line 1:
ORA-29273: HTTP request failed
ORA-06512: at "SYS.UTL_HTTP", line 1577
ORA-24247: network access denied by access control list (ACL)
ORA-06512: at line 1

Note the error "ORA-24247: network access denied by access control list (ACL)." The user called the http server on port 80, which is outside the allowed range 22-55. Therefore the action was prevented. 
Now, add another rule to allow the communication:

  1  begin
  2    dbms_network_acl_admin.assign_acl (
  3    acl => 'utlpkg.xml',
  4    host => '
www.proligence.com',
  5    lower_port => 1,
  6    upper_port => 10000);
  7* end;
  8  /
 
PL/SQL procedure successfully completed.
 
SQL> conn scott/tiger
Connected.
SQL> select utl_http.request('
http://www.proligence.com') from dual;
 
UTL_HTTP.REQUEST('
HTTP://WWW.PROLIGENCE.COM')
--------------------------------------------------------------------------------
</iframe><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD><TITLE>Proligence Home</TITLE>
<META http-equiv=Content-Language content=en-us>

No comments: