Hey, what's up, Gurus?
In this lesson, we are going to talk about
how to implement resource tokens in Azure Databricks.
So we're going to talk first a little bit,
conceptually, about how we authenticate in Azure Databricks,
and then we're going to spend most of our time
actually in the portal.
I'm going to jump over, and I'm going to show you
how to actually set this up.
So with that, let's get started.
So when we authenticate in Databricks,
there's basically 2 different options.
The first option is to authenticate
using an Azure Active Directory token that you can create.
And so to do that,
you're going to define the service principal in Azure AD,
and then you're going to get an Azure AD access token.
That's really the 2 steps
that you need to do in order to get
an Azure Active Directory token for Databricks.
The second option is to use
an Azure Databricks personal access token,
and I'll show you how to do that as well.
When you look at authentication,
tokens should be used in place of passwords
as much as possible.
You certainly don't want to hardcode any passwords
into your environment or into your scripts or codes.
So you want to use these tokens
and these authentication methods instead,
because it's so much easier
and safer to retract those tokens, to expire those tokens,
and to manage who has access to the environments.
So with that, let's actually hop into the portal,
and spend the rest of the time taking a look
at how we create and revoke tokens in Databricks.
So let me jump you over, and let's go ahead
and actually tackle the Azure Active Directory one first.
So I'll take you into Azure Active Directory,
and we've gone down to Manage and then App Registrations.
So we need to create an application registration first.
And so I've actually done that here,
but I'll show you what this looks like.
If I click on New Registration,
basically I just create a name.
And then I choose who can use the application.
Generally, you're probably going to have a single tenant,
but again, if this is not-
if this is a production environment,
it very likely may be multi-tenant, or whatever.
So for our case, we would just choose single tenant.
Then, we would just create a redirect URI if we have that,
otherwise, we can just leave that alone.
And then we just click on Register.
And it's just going to take a second here,
and there you go.
It's actually created that registration.
Once we have that registration,
we need to go in and create our token.
And so to do that,
I'm going to go under Manage, Certificates & Secrets,
and then I'm going to create a new client secret.
So I could just say this is my 'Databricks test'.
I can choose my expiration date,
custom or I can choose from a dropdown list here.
Click on Add, and then it's going to give me my information.
Now, another key point here.
I am going to be deleting this as soon as we're done,
so the secret ID and the value really isn't that important.
However, in a real environment
or in your environment, it is incredibly important,
please don't share this with people. Okay?
So if you want to use Azure Active Directory,
this is how you would do that to generate a token.
The other option is to go into Databricks,
and I would come down to Settings,
User Settings, and then that takes me here,
and I can create an access token.
I just click on Generate Token,
and I would just say 'test', set my duration again,
click on Generate. There's my token.
And here is my token now displayed here.
Now, let's say that I need to remove a token,
because oops, I showed it to everyone in a video.
I would come over here, and I can click on the X button,
and I can revoke the token.
So I just click on Revoke, and there you go.
That quick, it has been deleted.
Same thing is true over here.
I can come back to this, and I can revoke
a client's secret by simply coming over here
and clicking on my trash can icon.
And you can see that quickly,
it has deleted my client's secret.
So this is a fantastic way to manage tokens
and manage access into your Databricks environment.
Couple of key points to remember.
One, you need an authentication flow.
Make sure that you're not using passwords,
make sure that you have a flow of authentication,
and then you can remove that flow as needed.
And don't forget, there's 2 ways to authenticate.
This is important for the DP-203.
You can use your Azure Active Directory tokens
or you can use personal access tokens in Azure Databricks.
That's it for this lesson.
I'll see you in the next.