Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
56b7e2df
Commit
56b7e2df
authored
Aug 24, 2016
by
Joe Lanford
Committed by
Daniel Lee
Nov 24, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for TLS client auth for datasource proxies (#5801)
parent
ad7ae1b9
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
88 additions
and
4 deletions
+88
-4
pkg/api/app_routes.go
+16
-1
pkg/api/dataproxy.go
+20
-3
pkg/api/datasources.go
+4
-0
pkg/api/dtos/models.go
+3
-0
pkg/models/datasource.go
+9
-0
pkg/services/sqlstore/datasource.go
+7
-0
pkg/services/sqlstore/migrations/datasource_mig.go
+11
-0
public/app/features/plugins/partials/ds_http_settings.html
+18
-0
No files found.
pkg/api/app_routes.go
View file @
56b7e2df
package
api
import
(
"crypto/tls"
"net"
"net/http"
"time"
"gopkg.in/macaron.v1"
"github.com/grafana/grafana/pkg/api/pluginproxy"
...
...
@@ -11,6 +16,16 @@ import (
"github.com/grafana/grafana/pkg/util"
)
var
pluginProxyTransport
=
&
http
.
Transport
{
TLSClientConfig
:
&
tls
.
Config
{
InsecureSkipVerify
:
true
},
Proxy
:
http
.
ProxyFromEnvironment
,
Dial
:
(
&
net
.
Dialer
{
Timeout
:
30
*
time
.
Second
,
KeepAlive
:
30
*
time
.
Second
,
})
.
Dial
,
TLSHandshakeTimeout
:
10
*
time
.
Second
,
}
func
InitAppPluginRoutes
(
r
*
macaron
.
Macaron
)
{
for
_
,
plugin
:=
range
plugins
.
Apps
{
for
_
,
route
:=
range
plugin
.
Routes
{
...
...
@@ -40,7 +55,7 @@ func AppPluginRoute(route *plugins.AppPluginRoute, appId string) macaron.Handler
path
:=
c
.
Params
(
"*"
)
proxy
:=
pluginproxy
.
NewApiPluginProxy
(
c
,
path
,
route
,
appId
)
proxy
.
Transport
=
data
ProxyTransport
proxy
.
Transport
=
plugin
ProxyTransport
proxy
.
ServeHTTP
(
c
.
Resp
,
c
.
Req
.
Request
)
}
}
pkg/api/dataproxy.go
View file @
56b7e2df
...
...
@@ -17,14 +17,27 @@ import (
"github.com/grafana/grafana/pkg/util"
)
var
dataProxyTransport
=
&
http
.
Transport
{
TLSClientConfig
:
&
tls
.
Config
{
InsecureSkipVerify
:
true
},
func
dataProxyTransport
(
ds
*
m
.
DataSource
)
(
*
http
.
Transport
,
error
)
{
transport
:=
&
http
.
Transport
{
TLSClientConfig
:
&
tls
.
Config
{
InsecureSkipVerify
:
true
,
},
Proxy
:
http
.
ProxyFromEnvironment
,
Dial
:
(
&
net
.
Dialer
{
Timeout
:
30
*
time
.
Second
,
KeepAlive
:
30
*
time
.
Second
,
})
.
Dial
,
TLSHandshakeTimeout
:
10
*
time
.
Second
,
}
if
ds
.
TlsAuth
{
cert
,
err
:=
tls
.
LoadX509KeyPair
(
ds
.
TlsClientCert
,
ds
.
TlsClientKey
)
if
err
!=
nil
{
return
nil
,
err
}
transport
.
TLSClientConfig
.
Certificates
=
[]
tls
.
Certificate
{
cert
}
}
return
transport
,
nil
}
func
NewReverseProxy
(
ds
*
m
.
DataSource
,
proxyPath
string
,
targetUrl
*
url
.
URL
)
*
httputil
.
ReverseProxy
{
...
...
@@ -128,7 +141,11 @@ func ProxyDataSourceRequest(c *middleware.Context) {
}
proxy
:=
NewReverseProxy
(
ds
,
proxyPath
,
targetUrl
)
proxy
.
Transport
=
dataProxyTransport
proxy
.
Transport
,
err
=
dataProxyTransport
(
ds
)
if
err
!=
nil
{
c
.
JsonApiErr
(
400
,
"Unable to load TLS certificate"
,
err
)
return
}
proxy
.
ServeHTTP
(
c
.
Resp
,
c
.
Req
.
Request
)
c
.
Resp
.
Header
()
.
Del
(
"Set-Cookie"
)
}
pkg/api/datasources.go
View file @
56b7e2df
...
...
@@ -33,6 +33,7 @@ func GetDataSources(c *middleware.Context) {
Database
:
ds
.
Database
,
User
:
ds
.
User
,
BasicAuth
:
ds
.
BasicAuth
,
TlsAuth
:
ds
.
TlsAuth
,
IsDefault
:
ds
.
IsDefault
,
JsonData
:
ds
.
JsonData
,
}
...
...
@@ -165,6 +166,9 @@ func convertModelToDtos(ds *m.DataSource) dtos.DataSource {
BasicAuth
:
ds
.
BasicAuth
,
BasicAuthUser
:
ds
.
BasicAuthUser
,
BasicAuthPassword
:
ds
.
BasicAuthPassword
,
TlsAuth
:
ds
.
TlsAuth
,
TlsClientCert
:
ds
.
TlsClientCert
,
TlsClientKey
:
ds
.
TlsClientKey
,
WithCredentials
:
ds
.
WithCredentials
,
IsDefault
:
ds
.
IsDefault
,
JsonData
:
ds
.
JsonData
,
...
...
pkg/api/dtos/models.go
View file @
56b7e2df
...
...
@@ -77,6 +77,9 @@ type DataSource struct {
BasicAuth
bool
`json:"basicAuth"`
BasicAuthUser
string
`json:"basicAuthUser"`
BasicAuthPassword
string
`json:"basicAuthPassword"`
TlsAuth
bool
`json:"tlsAuth"`
TlsClientCert
string
`json:"tlsClientCert"`
TlsClientKey
string
`json:"tlsClientKey"`
WithCredentials
bool
`json:"withCredentials"`
IsDefault
bool
`json:"isDefault"`
JsonData
*
simplejson
.
Json
`json:"jsonData,omitempty"`
...
...
pkg/models/datasource.go
View file @
56b7e2df
...
...
@@ -43,6 +43,9 @@ type DataSource struct {
BasicAuth
bool
BasicAuthUser
string
BasicAuthPassword
string
TlsAuth
bool
TlsClientCert
string
TlsClientKey
string
WithCredentials
bool
IsDefault
bool
JsonData
*
simplejson
.
Json
...
...
@@ -87,6 +90,9 @@ type AddDataSourceCommand struct {
BasicAuth
bool
`json:"basicAuth"`
BasicAuthUser
string
`json:"basicAuthUser"`
BasicAuthPassword
string
`json:"basicAuthPassword"`
TlsAuth
bool
`json:"tlsAuth"`
TlsClientCert
string
`json:"tlsClientCert"`
TlsClientKey
string
`json:"tlsClientKey"`
WithCredentials
bool
`json:"withCredentials"`
IsDefault
bool
`json:"isDefault"`
JsonData
*
simplejson
.
Json
`json:"jsonData"`
...
...
@@ -108,6 +114,9 @@ type UpdateDataSourceCommand struct {
BasicAuth
bool
`json:"basicAuth"`
BasicAuthUser
string
`json:"basicAuthUser"`
BasicAuthPassword
string
`json:"basicAuthPassword"`
TlsAuth
bool
`json:"tlsAuth"`
TlsClientCert
string
`json:"tlsClientCert"`
TlsClientKey
string
`json:"tlsClientKey"`
WithCredentials
bool
`json:"withCredentials"`
IsDefault
bool
`json:"isDefault"`
JsonData
*
simplejson
.
Json
`json:"jsonData"`
...
...
pkg/services/sqlstore/datasource.go
View file @
56b7e2df
...
...
@@ -80,6 +80,9 @@ func AddDataSource(cmd *m.AddDataSourceCommand) error {
BasicAuth
:
cmd
.
BasicAuth
,
BasicAuthUser
:
cmd
.
BasicAuthUser
,
BasicAuthPassword
:
cmd
.
BasicAuthPassword
,
TlsAuth
:
cmd
.
TlsAuth
,
TlsClientCert
:
cmd
.
TlsClientCert
,
TlsClientKey
:
cmd
.
TlsClientKey
,
WithCredentials
:
cmd
.
WithCredentials
,
JsonData
:
cmd
.
JsonData
,
Created
:
time
.
Now
(),
...
...
@@ -126,6 +129,9 @@ func UpdateDataSource(cmd *m.UpdateDataSourceCommand) error {
BasicAuth
:
cmd
.
BasicAuth
,
BasicAuthUser
:
cmd
.
BasicAuthUser
,
BasicAuthPassword
:
cmd
.
BasicAuthPassword
,
TlsAuth
:
cmd
.
TlsAuth
,
TlsClientCert
:
cmd
.
TlsClientCert
,
TlsClientKey
:
cmd
.
TlsClientKey
,
WithCredentials
:
cmd
.
WithCredentials
,
JsonData
:
cmd
.
JsonData
,
Updated
:
time
.
Now
(),
...
...
@@ -133,6 +139,7 @@ func UpdateDataSource(cmd *m.UpdateDataSourceCommand) error {
sess
.
UseBool
(
"is_default"
)
sess
.
UseBool
(
"basic_auth"
)
sess
.
UseBool
(
"tls_auth"
)
sess
.
UseBool
(
"with_credentials"
)
_
,
err
:=
sess
.
Where
(
"id=? and org_id=?"
,
ds
.
Id
,
ds
.
OrgId
)
.
Update
(
ds
)
...
...
pkg/services/sqlstore/migrations/datasource_mig.go
View file @
56b7e2df
...
...
@@ -101,4 +101,15 @@ func addDataSourceMigration(mg *Migrator) {
mg
.
AddMigration
(
"Add column with_credentials"
,
NewAddColumnMigration
(
tableV2
,
&
Column
{
Name
:
"with_credentials"
,
Type
:
DB_Bool
,
Nullable
:
false
,
Default
:
"0"
,
}))
// add columns to activate TLS client auth option
mg
.
AddMigration
(
"Add column tls_auth"
,
NewAddColumnMigration
(
tableV2
,
&
Column
{
Name
:
"tls_auth"
,
Type
:
DB_Bool
,
Nullable
:
false
,
Default
:
"0"
,
}))
mg
.
AddMigration
(
"Add column tls_client_cert"
,
NewAddColumnMigration
(
tableV2
,
&
Column
{
Name
:
"tls_client_cert"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
true
,
}))
mg
.
AddMigration
(
"Add column tls_client_key"
,
NewAddColumnMigration
(
tableV2
,
&
Column
{
Name
:
"tls_client_key"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
true
,
}))
}
public/app/features/plugins/partials/ds_http_settings.html
View file @
56b7e2df
...
...
@@ -49,6 +49,10 @@
label=
"With Credentials"
checked=
"current.withCredentials"
switch-class=
"max-width-6"
>
</gf-form-switch>
<gf-form-switch
class=
"gf-form"
ng-if=
"current.access=='proxy'"
label=
"TLS Client Auth"
checked=
"current.tlsAuth"
switch-class=
"max-width-6"
>
</gf-form-switch>
</div>
<div
class=
"gf-form"
ng-if=
"current.basicAuth"
>
...
...
@@ -64,5 +68,19 @@
</span>
<input
class=
"gf-form-input max-width-21"
type=
"password"
ng-model=
'current.basicAuthPassword'
placeholder=
"password"
required
></input>
</div>
<div
class=
"gf-form"
ng-if=
"current.tlsAuth && current.access=='proxy'"
>
<span
class=
"gf-form-label width-7"
>
Client Cert
</span>
<input
class=
"gf-form-input max-width-23"
type=
"text"
ng-model=
'current.tlsClientCert'
placeholder=
"cert path"
required
></input>
</div>
<div
class=
"gf-form"
ng-if=
"current.tlsAuth && current.access=='proxy'"
>
<span
class=
"gf-form-label width-7"
>
Client Key
</span>
<input
class=
"gf-form-input max-width-23"
type=
"text"
ng-model=
'current.tlsClientKey'
placeholder=
"key path"
required
></input>
</div>
</div>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment