I'm trying to open a python connection to Redshift from Sagemaker Jupiter notebook. It works fine with psycopg2 method when I pass user name and password, however I now want to connect using OKTA Authentication and for that purpose I shouldn't pass in username and password but I'd like to pass in a jdbc URL with all connection string parameters like DBGroups, Login_url etc that will allow me to authenticate via OKTA. that I already have correct. Do you know if this is possible?
Related
Currently I am using (of course with more elaborate variables):
conn = openstack.connect(
load_yaml_config=False,
load_envvars=False,
auth_url=AL,
project_name=PN,
username=UN,
password=PW,
region_name=RN,
user_domain_name=UDN,
project_domain_name=PDN,
app_name=42,
app_version=42
)
to connect to projects. But in the future I would like to offer using application credentials, too. While there is plenty of documentation on how to authenticate with said credentials, I can't find anything about authenticating a connection with it. How is it done?
So what I am looking for is a way to create a connection without username and password, but credentials instead.
On connection: https://docs.openstack.org/openstacksdk/latest/user/connection.html
On application credentials: https://docs.openstack.org/keystone/queens/user/application_credentials.html
On rest-api calls https://docs.openstack.org/api-ref/identity/v3/index.html#application-credentials
Existing authenticated session
This might be an option:
From existing authenticated Session
-----------------------------------
For applications that already have an authenticated Session, simply passing
it to the :class:`~openstack.connection.Connection` constructor is all that
is needed:
.. code-block:: python
from openstack import connection
conn = connection.Connection(
session=session,
region_name='example-region',
compute_api_version='2',
identity_interface='internal')
but I have to investigate further.
I couldn't find any documentation, but apparently it is possible to create a connection like this:
openstack.connect(
load_yaml_config=False,
load_envvars=False,
auth_url=AU,
region_name=RN,
application_credential_id=ACI,
application_credential_secret=ACS,
auth_type=AT
)
and that will return a connection object just like before. auth_type has to be "v3applicationcredential" when using application credentials.
I am a bit stuck here, so i made a test site to figure this out.
I have a python flask site and I have to use the domain login to login into sql database. Here i wrote a quick test which sends the username and password to my db connection and will display the connection on the screen
#app.route("/", methods =['GET','POST']
def index():
user = os.environ.get('username')
pwd = os.environ.get('password')
dbcon = db.sqlcon(user, pwd)
return render_template("index.html", dbcon=dbcon
def dbcon(user, pwd):
a="SQL Server"
con = pyodbc.connect(f"DRIVER={a};Database=customer;Server=SQL1;Username={user};pwd{pwd}")
return con
Again, very simple and this works on my local machine. When i upload to the iis server, it does not connect to the database. I tried install an odbc driver on the iis server, but still wouldn't connect.
I also checked to see, when i go onto the site from the server, it does capture my login information.
Any help is duly appreciated
DamnGroundHog
I use flask on IIS and work perfect wit SQL.(thanks from this link ).
First step create SQL authentication user on SQL server with SQL server management.
second step connect with this code:
coonection = pyodbc.connect("Driver={ODBC Driver 17 for SQL Server};Server=. ;Database=MyDBName;uid=UserNameWhenCreateUser; pwd=PasswordWhenCreateUser;")
CU = coonection .cursor()
result:
I'm trying to connect my Databricks cluster to an existing SQL Server database using python. I will like to leverage the integrated authentication method. Getting error com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication.
jdbcHostname = "sampledb-dev.database.windows.net"
jdbcPort= 1433
jdbcDatabase = "sampledb-dev"
jdbcUrl = "jdbc:sqlserver://{0}:{1}; database={2}".format(jdbcHostname, jdbcPort, jdbcDatabase)
connectionProperties={
"integratedSecurity" : "true",
"driver" : "com.microsoft.sqlserver.jdbc.SQLServerDriver"
}
print(jdbcUrl)
query ="(SELECT * FROM TABLE1.Domain)"
domains = spark.read.jdbc(url = jdbcUrl, table = query, properties = connectionProperties)
display(domains)
You can't use integratedSecurity=true with an Azure PaaS database. IntegratedSecurity is an on-premise construct.
You need to use authentication=ActiveDirectoryIntegrated or authentication=ActiveDirectoryPassword, please see JDBC docs here:
https://learn.microsoft.com/en-us/sql/connect/jdbc/connecting-using-azure-active-directory-authentication?view=sql-server-ver15
You will also need your account to be user with appropriate permissions to that database which is synch'd to Azure AD. If you use multi-factor authentication, then that's not supported for JDBC and your admin will need to provide you with a non-MFA enabled account. You'll know if this is the case because you will get a WSTrust error when trying to connect.
I am using the MongoDB on my app and when I try to access the database directly using the service connector, I am able to connect but then I am getting :
Error: error: {
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { *any command*}",
"code" : 13
}
and this on any query or command.
Is there a way to change authorization or accessing the data of my MongoDB
P.S: My MongoDB was bind as in the tutorial: https://docs.developer.swisscom.com/tutorial-python/bind-service.html
It looks like you're trying to execute commands on the admin database on which your user is not authorized. You can find the correct database which your user is authorized on in the credentials (key mongodb.credentials.database) but ideally you connect using the provided URI (mongodb.credentials.uri) which will connect you to the correct database automatically.
You can have a look at the Python example in the tutorial you linked to find out how to access and use those credentials correctly.
The answer from Sandro Mathys is correct and helpful, I wish to clarify/simplyfy a little bit.
The service broker grants you the Role dbOwner and creates a database with random name for you. This is done during cf create-service process.
The database owner can perform any administrative action on the
database. This role combines the privileges granted by the readWrite,
dbAdmin and userAdmin roles.
You have no privileges on admin database. The admin database is only for Swisscom operators. Please use for login with mongo shell the parameter --authenticationDatabase with the random database name from cf env.
Specifies the database in which the user is created. See Authentication Database.
If you do not specify a value for --authenticationDatabase, mongo uses the database specified in the connection string.
I am new to mongodb and I am trying to connect it remotely (from my local system to live db) and it is connected successfully. I have admin users in admin table and want that without authentication no one can access my database. But when I try to connect Mongodb remotely via the below mention code , even without authentication i can access any db :
from pymongo import MongoClient, Connection
c = MongoClient('myip',27017)
a = c.mydb.testData.find()
In my config file , the parameter auth is set to True , auth = True . But still no authentication is needed to access my db . Please can anyone let me know what I am missing here.
Based on your description I would guess you haven't actually enabled authentication. In order to enable authentication you must start the Mongo server with certain settings. You can find more information below:
http://docs.mongodb.org/manual/tutorial/enable-authentication/
Basically you need to run with --auth in order to enable authentication.