ORDS ORA-01031: insufficient privileges - oracle

During installation, ORDS created a TEST user and granted rights, according to the instructions
1.3.4.1 ORDS Installer Privileges Script.
Issued the appropriate rights.
But when trying to enable AUTOREST with (under user TEST):
BEGIN
ORDS.ENABLE_OBJECT(p_enabled => TRUE,
p_schema => 'MAIN',
p_object => 'SOME_TABLE',
p_object_type => 'TABLE',
p_object_alias => 'some_table',
p_auto_rest_auth => FALSE);
commit;
END;
I get:
[Error] Execution (49:1): ORA-01031: insufficient privileges
ORA-06512: at "ORDS_METADATA.ORDS", line 310
ORA-06512: at line 3
Oracle 11.2.0.4
ORDS latest
APEX 20.02

You have to use the ORDS_ADMIN package to enable a schema or object other than your own.
To use this package, your user needs the ORDS Administrator role.
So, do this
GRANT ORDS_ADMINISTRATOR_ROLE TO HR_ADMIN;
Then login as TEST and run this
BEGIN
ORDS_ADMIN.ENABLE_OBJECT(p_enabled => TRUE,
p_schema => 'MAIN',
p_object => 'SOME_TABLE',
p_object_type => 'TABLE',
p_object_alias => 'some_table',
p_auto_rest_auth => FALSE);
commit;
END;
Disclaimer: I work for Oracle and am a product manager on the database team and cover ORDS.

Related

Procedure to move oracledb export to s3 bucket fails when ran in a job

Job fails with:
ORA-29481: Implicit results cannot be returned to client.
ORA-06512: at "SYS.DBMS_SQL", line 2832
ORA-06512: at "SYS.DBMS_SQL", line 2826
ORA-06512: at "owner.SEND_TO_S3", line 8
ORA-06512: at line 1
I can run the procedure manually(BEGIN SEND_TO_S3; END;) without errors and the db exports
show up in the s3 bucket.
****Oracle Job
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'SEND_EXP_TO_S3_JOB',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN SEND_TO_S3; END;',
start_date => SYSTIMESTAMP,
enabled => TRUE,
repeat_interval => 'freq=weekly; byday=mon; byhour=20; byminute=40; bysecond=0;');
END;
****Oracle procedure
(If there some other way than to use a refcursor that might solve this issue as well)
CREATE OR REPLACE PROCEDURE send_to_s3
AS
rc sys_refcursor;
BEGIN
open rc for
SELECT
rdsadmin.rdsadmin_s3_tasks.upload_to_s3(
p_bucket_name => 'bucket/name',
p_prefix => 'EXP',
p_s3_prefix => '',
p_directory_name => 'DATA_PUMP_DIR') `your text`
AS TASK_ID FROM DUAL;
DBMS_SQL.RETURN_RESULT(rc);
END send_to_s3;
****The oracle error points to an outdated client but I have the latest client and I'm
not sure the scheduler uses a client.
Is there a way to get this job running correctly?

Insufficient privilege DBMS_SCHEDULER job

I have created a job in Oracle using following scheduler -
BEGIN
DBMS_SCHEDULER.create_job (
job_name => 'MY_JOB',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN my_pkg.pull_data(''Y''); END;',
start_date => '31-AUG-21 07.00.00 PM America/New_York',
repeat_interval => 'freq=daily; byminute=0; bysecond=0;',
enabled => TRUE);
END;
/
When I am running job manually using below code -
BEGIN
DBMS_SCHEDULER.RUN_JOB(
JOB_NAME => 'MY_JOB',
USE_CURRENT_SESSION => FALSE);
END;
The job is running as expected. However, scheduled same jobs are failed again and again with below error.
ORA-01031: insufficient privileges ORA-06512: at "SCOTT.MY_PKG", line 246 ORA-06512: at line 1
Any suggestion, what I am doing wrong? I think I have sufficient privileges.
Edit - If I call, individual procedure which is used in the job, it's working as expected. I have checked the line 246, which is a select statement from a table in the same schema as job, proc and other tables used by the proc.
BEGIN my_pkg.pull_data('Y'); END;

ORA-24247: network access denied by access control list (ACL) while sending email oracle

i have done all the activity i.e mention below, please tell which step / activity i am missing.
BEGIN
DBMS_NETWORK_ACL_ADMIN.CREATE_ACL(
acl => 'apex_user.xml',
description => 'access to apex email',
principal => 'DBUSER',
is_grant => TRUE,
privilege => 'connect',
start_date => SYSTIMESTAMP,
end_date =>Null
);
COMMIT;
END;
BEGIN
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(
acl => 'apex_user.xml',
principal => 'DBUSER',
is_grant => true,
privilege => 'resolve'
);
COMMIT;
END;
BEGIN
DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL(
acl => 'apex_user.xml',
host => 'smtp.gmail.com',
lower_port =>587,
upper_port =>587
);
COMMIT;
END;
to make sure the user can access the smtp packages, Run as SYS
GRANT EXECUTE ON UTL_TCP TO DBUSER;
GRANT EXECUTE ON UTL_SMTP TO DBUSER;
GRANT EXECUTE ON UTL_MAIL TO DBUSER;
GRANT EXECUTE ON UTL_http TO DBUSER;
Enabling UTL_MAIL
alter system set smtp_out_server = 'smtp.gmail.com:587' scope = both;
Once i execute following query in Oracle since fistname.lastname#gmail.com having less secure app as true from google account
begin
utl_mail.send(
sender => 'fistname.lastname#gmail.com',
recipients => 'fistname.lastname#gmail.com',
message => 'Hello World'
);
end;
Error report -
ORA-29279: SMTP permanent error: 530 5.7.0 Must issue a STARTTLS command first
and give error once call from apex as
APEX_MAIL.SEND(
p_to => 'fistname.lastname#gmail.com',
p_from => 'fistname.lastname#gmail.com',
p_subj => 'APEX_MAIL with attachment',
p_body => 'Please review the attachment.',
p_body_html => '<b>Please</b> review the attachment');
ORA-24247: network access denied by access control list (ACL)
however i tried using utl_smtp and again same error
create or replace PROCEDURE send_email(p_to IN VARCHAR2,
p_from IN VARCHAR2,
p_message IN VARCHAR2,
p_smtp_host IN VARCHAR2,
p_smtp_port IN NUMBER DEFAULT 587)
AS
l_mail_conn UTL_SMTP.connection;
BEGIN
l_mail_conn := UTL_SMTP.open_connection(p_smtp_host, p_smtp_port);
UTL_SMTP.helo(l_mail_conn, p_smtp_host);
UTL_SMTP.mail(l_mail_conn, p_from);
UTL_SMTP.rcpt(l_mail_conn, p_to);
UTL_SMTP.data(l_mail_conn, p_message || UTL_TCP.crlf || UTL_TCP.crlf);
UTL_SMTP.quit(l_mail_conn);
END;
ORA-29279: SMTP permanent error: 530 5.7.0 Must issue a STARTTLS command first. c13sm6735648wrb.38 - gsmtp
please tell which command or anything misisng..
You don't need any commit, since explicit DML operations are not performed for these operations. And using begin..end blocks not needed for every method invoking, either.
Your issue stems from the fact the neccessity of invoking Dbms_Network_Acl_Admin.Add_Privilege method with privilege => 'connect' option also. So you can use the following :
BEGIN
DBMS_NETWORK_ACL_ADMIN.CREATE_ACL(
acl => 'apex_user.xml',
description => 'access to apex email',
principal => 'DBUSER',
is_grant => TRUE,
privilege => 'connect',
start_date => SYSTIMESTAMP,
end_date =>Null
);
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(
acl => 'apex_user.xml',
principal => 'DBUSER',
is_grant => true,
privilege => 'connect'
);
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(
acl => 'apex_user.xml',
principal => 'DBUSER',
is_grant => true,
privilege => 'resolve'
);
DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL(
acl => 'apex_user.xml',
host => 'smtp.gmail.com',
lower_port =>587,
upper_port =>587
);
END;
With the following query all privileged accesses could be checked ( through SYS or SYSTEM schemas ):
select a.host,p.*
from dba_network_acl_privileges p
join dba_network_acls a on a.aclid = p.aclid
order by a.host, p.principal, p.privilege;
1) IMHO smtp.gmail.com requires secured connection and authentication but package utl_mail is not supporting these functions. You can achieve this with utl_smtp.
2) The Apex_mail package run with the privileges of their definer (apex_scheama) and your acl list is defined for dbuser. Also here you have somehow do the smtp authentication .

Invalid ACL identifier

Im trying to make a REST API call from db and for that i have tried to create a ACL first.Below are the query,I tried to execute via sysdba user.Im getting error.
Can someone help me.
BEGIN
DBMS_NETWORK_ACL_ADMIN.create_acl (
acl => 'test_sx_acl_file.xml',
description => 'A test of the ACL functionality',
principal => 'node',
is_grant => TRUE,
privilege => 'connect',
start_date => SYSTIMESTAMP,
end_date => NULL);
end;
/
PL/SQL procedure successfully completed.
2)
BEGIN
DBMS_NETWORK_ACL_ADMIN.assign_acl ( acl => 'test_sx_acl_file.xml ', host => '*.testapi.com', lower_port => NULL, upper_port => NULL);
END;
/
ERROR at line 1:
ORA-46059: Invalid ACL identifier specified
ORA-06512: at "SYS.DBMS_NETWORK_ACL_ADMIN", line 70
ORA-06512: at "SYS.DBMS_NETWORK_ACL_ADMIN", line 484
ORA-06512: at line 2
Why is that? what could be the reason

Run exe using trigger from Oracle database

I am trying to run exe from oracle database.
I want to fire a trigger on insert or updation of a table. Once table is updated i have to run my exe which is in my D drive.
I have tried scheduler but it gives error.
my code is as follows:
BEGIN
DBMS_SCHEDULER.CREATE_PROGRAM (
program_name => 'program_name',
program_type => 'EXECUTABLE',
program_action => 'D:/myproc.exe',
enabled => TRUE,
comments => 'run exe'
);
END;
/
I am getting following error
ORA-27486: insufficient privileges
ORA-06512: at "SYS.DBMS_ISCHED", line 5
ORA-06512: at "SYS.DBMS_SCHEDULER", line 36
ORA-06512: at line 2
I have one more question.
Which is best method to run exe? from database or from code?
Thanks in advance
You could schedule the script using DBMS_SCHEDULER.
Depending on your OS(below example in Windows) you could something like this:
BEGIN
dbms_scheduler.create_job('MY_JOB',
job_action=>'C:\WINDOWS\SYSTEM32\CMD.EXE',
number_of_arguments=>3,
job_type=>'executable',
start_date => SYSTIMESTAMP,
repeat_interval => 'freq=hourly; byminute=0,30; bysecond=0;',
end_date => NULL,
enabled=> false);
dbms_scheduler.set_job_argument_value('MY_JOB',1,'/q');
dbms_scheduler.set_job_argument_value('MY_JOB',2,'/c');
dbms_scheduler.set_job_argument_value('MY_JOB',3, 'D:/my_sql.bat.bat');
dbms_scheduler.enable('MY_JOB');
END;
/
Now your my_sql.bat would look like:
sqlplus user#sid/password #D:\scripts\script.sql
exit

Resources