Home » SQL & PL/SQL » SQL & PL/SQL » How to Restrict User from Connecting to Database Through Specific hostname (11g, 11.2.0.3, AIX 7.1.0.0)
How to Restrict User from Connecting to Database Through Specific hostname [message #619315] Mon, 21 July 2014 07:09 Go to next message
ashishkumarmahanta80
Messages: 231
Registered: October 2006
Location: kolkatta
Senior Member
Dear All,

Client requirement is to restrict user from Connecting to Database Through specific user HOST & DB User.

Below is my trigger -

CREATE OR REPLACE TRIGGER system.LOGON_DENY
AFTER LOGON
ON DATABASE
declare
OSUSER varchar2 (200);
HOSTNAME varchar2 (200);
       begin
       select sys_context ('USERENV', 'OS_USER') into OSUSER from dual;
       select sys_context ('USERENV', 'HOST') into HOSTNAME from dual;
        if sys_context('USERENV','SESSION_USER') in ('ASHISH','SCOTT','ASHISH2')    and  sys_context('USERENV', 'HOST') in ('ER02DSK40615002')
            then
  raise_application_error(-20022,'Denied!  You are not allowed to logon from host' );
         end if;
 end;
/


But when i logged on as SCOTT, ASHISH, system allowed to enter instead of firing trigger.

if I comment
and  sys_context('USERENV', 'HOST') in ('ER02DSK40615002')


trigger fire .

Please assist me to resolve this issue.

Regards,
Ashish Kumar Mahanta
Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619316 is a reply to message #619315] Mon, 21 July 2014 07:11 Go to previous messageGo to next message
Michel Cadot
Messages: 68643
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

So "sys_context('USERENV', 'HOST')" is not "ER02DSK40615002".

Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619319 is a reply to message #619316] Mon, 21 July 2014 07:58 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
And to confirm that(if you are still in doubt to Michel's reply) you could log the logon details and check.
Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619321 is a reply to message #619319] Mon, 21 July 2014 08:21 Go to previous messageGo to next message
Michel Cadot
Messages: 68643
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

I bet the user is connected from a Windows desktop and its logon host contains the domain name.

Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619347 is a reply to message #619321] Mon, 21 July 2014 14:30 Go to previous messageGo to next message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
its also possible that they have the dba group. Any user with the ADMINSTER DATABASE TRIGGER either directly or
indirectly through a role(DBA) cannot be prevented from logging in through the use of a trigger.
Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619356 is a reply to message #619347] Mon, 21 July 2014 20:12 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>trigger fire .
please post reproducible proof above is true.
Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619653 is a reply to message #619356] Thu, 24 July 2014 00:25 Go to previous messageGo to next message
ashishkumarmahanta80
Messages: 231
Registered: October 2006
Location: kolkatta
Senior Member
Dear All,

You all are correct. It's my mistake. Hostname I entered as domain name. When check with the session, come to know that machine name is
'<comp. name>/ER02DSK40615002'


Thanks to you all.

Regards,
Ashish Kumar Mahanta
Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619654 is a reply to message #619653] Thu, 24 July 2014 01:02 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Wow, Michel hit the bull's eye.

Thanks for the feedback Ashish.
Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619668 is a reply to message #619654] Thu, 24 July 2014 05:04 Go to previous messageGo to next message
ashishkumarmahanta80
Messages: 231
Registered: October 2006
Location: kolkatta
Senior Member
Dear All,

Now, I am facing another problem while trying to restrict remote hostname through the trigger.

Client is having tns-entry of the database. When logon by same database user, database is allowed, instead of restriction through trigger.

now, hostname is
'<comp. name>\ER03DSK40614266'


What needs to be check more on it?

Regards,
Ashish Kumar Mahanta
Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619671 is a reply to message #619668] Thu, 24 July 2014 05:36 Go to previous messageGo to next message
Michel Cadot
Messages: 68643
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
Client is having tns-entry of the database. When logon by same database user, database is allowed, instead of restriction through trigger.


Can't understand what does this mean.

Quote:
now, hostname is


So check this, or check only the second part, or check what you want.

We know only what you show us, so show us.

Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619676 is a reply to message #619671] Thu, 24 July 2014 05:58 Go to previous messageGo to next message
ashishkumarmahanta80
Messages: 231
Registered: October 2006
Location: kolkatta
Senior Member
Dear Michel,

In another system, pl/sql developer is installed which is having tns-entry of the database. Now, we want to restrict it from connecting to the database with the specified database users(from the hostname - '<comp. name>\ER03DSK40614266').

Hope, this time, I am able to understand you all.

Regards,
Ashish
Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619677 is a reply to message #619676] Thu, 24 July 2014 06:03 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
You just don't want the user to connect to the DB, is it that simple as I understand or something different?
Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619683 is a reply to message #619677] Thu, 24 July 2014 06:16 Go to previous messageGo to next message
ashishkumarmahanta80
Messages: 231
Registered: October 2006
Location: kolkatta
Senior Member
Yes Lalit.

CREATE OR REPLACE TRIGGER system.LOGON_DENY
AFTER LOGON
ON DATABASE
declare
OSUSER varchar2 (200);
HOSTNAME varchar2 (200);
       begin
       select sys_context ('USERENV', 'OS_USER') into OSUSER from dual;
       select sys_context ('USERENV', 'HOST') into HOSTNAME from dual;
        if sys_context('USERENV','SESSION_USER') in ('ASHISH','SCOTT','ASHISH2')    and  sys_context('USERENV', 'HOST') in ('<comp. name>\ER02DSK40615002')
            then
  raise_application_error(-20022,'Denied!  You are not allowed to logon from host' );
         end if;
 end;
/



Above trigger is okay, as I was checking for the same server. And it's working.

Now, I want to restrict by the same trigger to restrict remote session (hostname) for the specific username. As database is connecting without trigger gets fired.

Below is the host name -
'<comp. name>\ER03DSK40614266'


Regards,
Ashish
Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619686 is a reply to message #619683] Thu, 24 July 2014 06:36 Go to previous messageGo to next message
Michel Cadot
Messages: 68643
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Prove what you say.
Once again we know ONLY what you show us.
What's you tell us is just your interpretation of what you see, it is NOT what actually happens.
SHOW US.
And first show us the ACTUAL code.

Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619688 is a reply to message #619686] Thu, 24 July 2014 07:43 Go to previous messageGo to next message
ashishkumarmahanta80
Messages: 231
Registered: October 2006
Location: kolkatta
Senior Member
Dear Michel,

On hostname (<comp.name>\ER02DSK40615002), database is installed. Requirement is to restrict hostnames with specified username. eg
<comp.name>\ER02DSK40615002 >> SCOTT, ASHISH
<comp. name>\ER03DSK40614266 >> ASHISH, ASHISH2


In many machine, pl/sql developer is installed. We want to restrict specified database schemas from the trigger.

Trigger is as below -
CREATE OR REPLACE TRIGGER system.LOGON_DENY
AFTER LOGON
ON DATABASE
declare
OSUSER varchar2 (200);
HOSTNAME varchar2 (200);
       begin
       select sys_context ('USERENV', 'OS_USER') into OSUSER from dual;
       select sys_context ('USERENV', 'HOST') into HOSTNAME from dual;
        if sys_context('USERENV','SESSION_USER') in ('SCOTT','ASHISH2')    
        and  sys_context('USERENV', 'HOST') in ('CMCINDIA\ER02DSK40615002')  then
  raise_application_error(-20022,'Denied!  You are not allowed to logon from host' );
  elsif sys_context ('USERENV','SESSION_USER') in ('ASHISH','ASHISH2')    
        and  sys_context ('USERENV', 'HOST') in ('CMCINDIA\ER03DSK40614266')
        then
  raise_application_error(-20022,'Denied!  You are not allowed to logon from host' );
         end if;
 end;
/


Hope, this time, I am able to clear you all.

Regards,
Ashish
Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619689 is a reply to message #619315] Thu, 24 July 2014 07:43 Go to previous messageGo to next message
EdStevens
Messages: 1376
Registered: September 2013
Senior Member
It seems to me your approach to "security" is fundamentally flawed.

You are trying to prevent user 'A' from connecting to the database when he is sitting at machine 'B'. So what happens when machine 'B' is replaced by machine 'C', or user 'A' steps into the next cube and uses machine 'D'?

Step back for a moment. Forget any and all technical implementations or solutions. Describe the business problem you are trying to solve.
Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619692 is a reply to message #619688] Thu, 24 July 2014 07:55 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
ashishkumarmahanta80 wrote on Thu, 24 July 2014 18:13
We want to restrict specified database schemas from the trigger.


Why use trigger for this? I asked you if you completely want to restrict the user from accessing the database, you replied yes. Now you say you want to restrict the user from accessing specified schema. Then why to grant such privilege to the user at all? Can't you revoke the privileges already granted.
Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619781 is a reply to message #619692] Fri, 25 July 2014 01:06 Go to previous messageGo to next message
ashishkumarmahanta80
Messages: 231
Registered: October 2006
Location: kolkatta
Senior Member
Dear EdStevens,

Let me explain more clearly -

User A or B is not the major concern. Combination of user A or B & Machine "M" is major concern. If user A or B is using machine 'M", he should not be logged in by database user "SCOTT" or " ASHISH2". When user A or B is using machine "N", should not be logged in database user "ASHISH".

Dear Lalit,

I cannot revoke the privileges from the database users(SCHEMAS). Restriction is combinations of hostname & database users(schemas).

Hope, able to make you clear.

Regards,
Ashish Kumar Mahanta
Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619791 is a reply to message #619781] Fri, 25 July 2014 01:52 Go to previous messageGo to next message
Michel Cadot
Messages: 68643
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
If user A or B is using machine 'M", he should not be logged in by database user "SCOTT" or " ASHISH2". When user A or B is using machine "N", should not be logged in database user "ASHISH".


So write the test accordingly.


Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619818 is a reply to message #619791] Fri, 25 July 2014 04:12 Go to previous messageGo to next message
ashishkumarmahanta80
Messages: 231
Registered: October 2006
Location: kolkatta
Senior Member
Dear Michel,

My written trigger is not working. If you have any idea then please share.

Regards,
Ashish
Re: How to Restrict User from Connecting to Database Through Specific hostname [message #619859 is a reply to message #619818] Fri, 25 July 2014 10:20 Go to previous message
Michel Cadot
Messages: 68643
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

"Not working" is not an Oracle message.
Obviously your test is wrong, taking what your words:

Quote:
If user A or B is using machine 'M", he should not be logged in by database user "SCOTT" or " ASHISH2".

IF <user> IN ('SCOTT','ASHISH2) AND <machine> = 'M' THEN error

Quote:
When user A or B is using machine "N", should not be logged in database user "ASHISH".

IF <user> = 'ASHISH' AND <machine> = 'N' THEN error

Combining both:
IF ( <user> IN ('SCOTT','ASHISH2) AND <machine> = 'M' )
OR ( <user> = 'ASHISH' AND <machine> = 'N' )
THEN error


Previous Topic: Cocatenate (unload: function of sap hana) and each record of a coulmn which is a table name and run
Next Topic: Hierarchical query, rolling up value from child to parent
Goto Forum:
  


Current Time: Tue Apr 23 09:39:44 CDT 2024