Skip to Main Content
  • Questions
  • How to give a user edit privileges on another users packages

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question.

Asked: November 06, 2012 - 1:01 am UTC

Last updated: November 06, 2012 - 2:46 pm UTC

Version: 11.2.0.2

Viewed 10K+ times! This question is

You Asked

I got handed this requirement and I don't think there's a good way to solve it.
They have a user.. say USERA who has some tables, data, and packages. They want another user, say USERB who has select privilege on that data (easy enough).. the ability to make their own packages (easy enough).. but also want to give USERA the ability to edit USERB's packages. I think this is impossible without giving an ANY privilege. I think it best if USERA just has USERB's password. Any other solution?
Thanks.

and Tom said...

... I think it best if USERA just has USERB's password. ...

no, that would be a pretty bad idea.


you can allow A to assume B's identity

ops$tkyte%ORA11GR2> create user a identified by a;

User created.

ops$tkyte%ORA11GR2> grant create session, create procedure to a;

Grant succeeded.

ops$tkyte%ORA11GR2> 
ops$tkyte%ORA11GR2> create user b identified by b default tablespace users quota unlimited on users;

User created.

ops$tkyte%ORA11GR2> grant create session, create table, create procedure to b;

Grant succeeded.

ops$tkyte%ORA11GR2> 
ops$tkyte%ORA11GR2> alter user b grant connect through a;

User altered.

ops$tkyte%ORA11GR2> 
ops$tkyte%ORA11GR2> connect b/b
Connected.
b%ORA11GR2> create table t ( x int );

Table created.

b%ORA11GR2> create procedure p as begin null; end;
  2  /

Procedure created.

b%ORA11GR2> 
b%ORA11GR2> connect a/a
Connected.
a%ORA11GR2> show user
USER is "A"
a%ORA11GR2> connect a[b]/a
Connected.
b%ORA11GR2> show user
USER is "B"
b%ORA11GR2> create or replace procedure p as begin dbms_output.put_line( 'new stuff' ); end;
  2  /

Procedure created.

b%ORA11GR2> create table t2 ( x int );

Table created.

b%ORA11GR2> grant execute on p to a;

Grant succeeded.

b%ORA11GR2> connect a/a
Connected.
a%ORA11GR2> exec b.p
new stuff

PL/SQL procedure successfully completed.



so user A uses their own password to "become" B.

but that would give them the ability to do more than just edit B's packages - it would allow them to do anything B can do (as shown by creating a table)

we can restrict that somewhat by using roles - but not entirely (since some things will be granted directly to B)


ops$tkyte%ORA11GR2> create role b_role1;

Role created.

ops$tkyte%ORA11GR2> create role b_role2;

Role created.

ops$tkyte%ORA11GR2> 
ops$tkyte%ORA11GR2> grant create procedure, create session to b_role1;

Grant succeeded.

ops$tkyte%ORA11GR2> grant create table to b_role2;

Grant succeeded.

ops$tkyte%ORA11GR2> 
ops$tkyte%ORA11GR2> create user a identified by a;

User created.

ops$tkyte%ORA11GR2> grant create session, create procedure to a;

Grant succeeded.

ops$tkyte%ORA11GR2> 
ops$tkyte%ORA11GR2> create user b identified by b default tablespace users quota unlimited on users;

User created.

ops$tkyte%ORA11GR2> grant b_role1 to b;

Grant succeeded.

ops$tkyte%ORA11GR2> grant b_role2 to b;

Grant succeeded.

ops$tkyte%ORA11GR2> 
ops$tkyte%ORA11GR2> alter user b grant connect through a with role b_role1;

User altered.

ops$tkyte%ORA11GR2> 
ops$tkyte%ORA11GR2> connect b/b
Connected.
b%ORA11GR2> create table t ( x int );

Table created.

b%ORA11GR2> create procedure p as begin null; end;
  2  /

Procedure created.

b%ORA11GR2> 
b%ORA11GR2> connect a/a
Connected.
a%ORA11GR2> show user
USER is "A"
a%ORA11GR2> connect a[b]/a
Connected.
b%ORA11GR2> show user
USER is "B"
b%ORA11GR2> create or replace procedure p as begin dbms_output.put_line( 'new stuff' ); end;
  2  /

Procedure created.

b%ORA11GR2> create table t2 ( x int );
create table t2 ( x int )
*
ERROR at line 1:
ORA-01031: insufficient privileges


b%ORA11GR2> grant execute on p to a;

Grant succeeded.

b%ORA11GR2> connect a/a
Connected.
a%ORA11GR2> exec b.p
new stuff

PL/SQL procedure successfully completed.


here we made it so that A only has create session and create procedure when connected as B.

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Hey that's great

A reader, November 06, 2012 - 11:01 am UTC

I did not know about that grant "alter user b grant connect through a;"

Thanks.

seems to be a problem with SQL Navigator

A reader, November 06, 2012 - 2:35 pm UTC

which only allows alpha characters in the connect string. Is it possible it isn't possible to implement this if the users are using SQL*Navigator?
Tom Kyte
November 06, 2012 - 2:46 pm UTC

you need to ask the manufacturer of sql*navigator how to utilize this database feature that has been in Oracle since version 8i....


I'm not at all familiar with that tool

this connect string is a sqlplus connect string, it is not "standard" or anything. It is just sqlplus's way of getting the username, password and proxy user name

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library