Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Redis 6 ACL authentication #60

Merged
merged 3 commits into from
Aug 29, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pkg/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,14 @@ func newDataSourceInstance(setting backend.DataSourceInstanceSettings) (instance
connFunc := func(network, addr string) (radix.Conn, error) {
opts := []radix.DialOpt{radix.DialTimeout(time.Duration(timeout) * time.Second)}

// Add Password
// Authentication
if secureData != nil && secureData["password"] != "" {
opts = append(opts, radix.DialAuthPass(secureData["password"]))
// If ACL enabled
if jsonData.ACL {
opts = append(opts, radix.DialAuthUser(jsonData.User, secureData["password"]))
} else {
opts = append(opts, radix.DialAuthPass(secureData["password"]))
}
}

// TLS Authentication
Expand Down
2 changes: 2 additions & 0 deletions pkg/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type dataModel struct {
TLSSkipVerify bool `json:"tlsSkipVerify"`
Client string `json:"client"`
SentinelName string `json:"sentinelName"`
ACL bool `json:"acl"`
User string `json:"user"`
}

/*
Expand Down
26 changes: 26 additions & 0 deletions src/components/ConfigEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,32 @@ export class ConfigEditor extends PureComponent<Props, State> {
/>
</div>

<div className="gf-form">
<Switch
label="ACL"
labelClass="width-10"
tooltip="Allows certain connections to be limited in terms of the commands that can be executed and the keys that can be accessed"
checked={jsonData.acl || false}
onChange={(event) => {
const jsonData = { ...options.jsonData, acl: event.currentTarget.checked };
onOptionsChange({ ...options, jsonData });
}}
/>

{jsonData.acl && (
<FormField
label="Username"
labelWidth={10}
inputWidth={10}
value={jsonData.user}
tooltip="Provide ACL Username to authenticate."
onChange={(event: ChangeEvent<HTMLInputElement>) => {
onOptionsChange({ ...options, jsonData: { ...options.jsonData, user: event.target.value } });
}}
/>
)}
</div>

<div className="gf-form">
<SecretFormField
isConfigured={(secureJsonFields && secureJsonFields.password) as boolean}
Expand Down
18 changes: 16 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ export interface RedisDataSourceOptions extends DataSourceJsonData {
* @type {string}
*/
sentinelName: string;

/**
* ACL enabled
*
* @type {boolean}
*/
acl: boolean;

/**
* ACL Username
*
* @type {string}
*/
user: string;
}

/**
Expand Down Expand Up @@ -108,8 +122,8 @@ export enum ClientTypeValue {
* Client Types
*/
export const ClientType = [
{ label: 'Redis Cluster', value: ClientTypeValue.CLUSTER },
{ label: 'Standalone', value: ClientTypeValue.STANDALONE },
{ label: 'Cluster', value: ClientTypeValue.CLUSTER },
{ label: 'Sentinel', value: ClientTypeValue.SENTINEL },
{ label: 'Socket', value: ClientTypeValue.SOCKET },
{ label: 'Standalone', value: ClientTypeValue.STANDALONE },
];