Commit Graph

4856 Commits

Author SHA1 Message Date
Oleg Gaidarenko
d88fdc86fc Auth: Do not search for the user twice (#18366)
* Auth: Do not search for the user twice

Previously `initContextWithBasicAuth` did not use `LoginUserQuery`, doing
`GetUserByLoginQuery` only i.e. looking user in DB only, things changed when
this function started to check LDAP provider via `LoginUserQuery` (#6940),
however, this request was placed after `GetUserByLoginQuery`, so we first
looking in DB then in the LDAP - if LDAP user hasn't logged in we will
not find it in DB, so `LoginUserQuery` will never be reached.

`LoginUserQuery` request already performs `GetUserByLoginQuery`
request in correct sequence. So we can just remove redundant request.

* Correct sequence execution during authentification &
  introduce tests for it

* Move basic auth tests to separate test file, since main test file already
  pretty large

* Introduce `testing.go` for the middleware module

* Remove redundant test helper function

* Make handler names more explicit

Ref 5777f65d05
Fixes #18329

* Auth: address review comment
2019-08-03 21:50:05 +02:00
Dominic Miglar
32d6740b8f Alerting: Also include configured AlertRuleTags in Webhooks (#18233)
* added alert rule tags in webhook notifications

* fix: don't include whole list of Tag objects but only key/value pairs in Webhook JSON

* marked webhook alerts to support alert rule tags
2019-08-03 17:00:40 +02:00
Oleg Gaidarenko
7e89a93b5f
Auth: introduce more tests for middleware module (#18365)
* Add tests for errors basic auth cases and moves tests to separate test-case.
Also names test cases consistently

* Add additional test helper

Ref 82661b9f69
2019-08-02 20:56:58 +03:00
Oleg Gaidarenko
fb273cb874
LDAP: nitpicks (#18309)
* LDAP: nitpicks

* Add more tests

* Correct and clarify comment for Login() method

* Rename methods (hail consistency!)

* Uppercases first letter of the logs everywhere

* Moves method definitions around to more appropriate places

Fixes #18295
2019-08-02 19:24:44 +03:00
Torkel Ödegaard
f3fb178efa Navigation: Fixed double settings menus (#18349) 2019-08-02 14:02:59 +02:00
Oleg Gaidarenko
82661b9f69 Auth: consistently return same basic auth errors (#18310)
* Auth: consistently return same basic auth errors

* Put repeated errors in consts and return only those consts as error strings

* Add tests for errors basic auth cases and moves tests to separate test-case.
  Also names test cases consistently

* Add more error logs and makes their messages consistent

* A bit of code style

* Add additional test helper

* Auth: do not expose even incorrect password

* Auth: address review comments

Use `Debug` for the cases when it's an user error
2019-08-02 11:16:31 +02:00
Leonard Gram
c675449aa2
cli: fix for recognizing when in dev mode. (#18334) 2019-08-02 09:38:41 +02:00
Sofia Papagiannaki
69b7b8bb46 Fix OAuth error due to SameSite cookie policy (#18332)
The `oauth_state` cookie used to be created with the SameSite value set
according to the `cookie_samesite` configuration.
However, due to a Safari bug SameSite=None or SameSite=invalid are treated
as Strict which results in "missing saved state" OAuth login failures
because the cookie is not sent with the redirect requests to the OAuth
provider.
This commit always creates the `oauth_state` cookie with SameSite=Lax
to compensate for this.
2019-08-01 15:47:04 +02:00
gotjosh
ed8aeb2999
Auth Proxy: Include additional headers as part of the cache key (#18298)
* Auth Proxy: Include additional headers as part of the cache key

Auth proxy has support to send additional user attributes as part of the
authentication flow. These attributes (e.g. Groups) need to be monitored
as part of the process in case of change.

This commit changes the way we compute the cache key to include all of the
attributes sent as part of the authentication request. That way, if we
change any user attributes we'll upsert the user information.
2019-07-31 11:23:00 +01:00
Andrej Ocenas
8c49d27705
CLI: Allow installing custom binary plugins (#17551)
Make sure all data is sent to API to be able to select correct archive version.
2019-07-29 10:44:58 +02:00
gotjosh
2f240a11ce SAML: Only show SAML login button on Enterprise version (#18270)
SAML Authentication is an Enterprise only feature. This change enables
the SAML login button to only be shown on enterprise.
2019-07-26 11:05:02 +02:00
Andrej Ocenas
7f1214ac46
Permissions: Show plugins in nav for non admin users but hide plugin configuration (#18234)
Allow non admins to see plugins list but only with readme. Any config tabs are hidden from the plugin page. Also plugin panel does not show action buttons (like Enable) for non admins.
2019-07-25 16:54:26 +02:00
Oleg Gaidarenko
1e5fc76601
LDAP: improve POSIX support (#18235)
* LDAP: improve POSIX support

* Correctly abtain DN attributes result

* Allow more flexibility with comparison mapping between POSIX group & user

* Add devenv for POSIX LDAP server

* Correct the docs

Fixes #18140
2019-07-24 12:49:18 +03:00
Dima Kurguzov
a4b0ccc138 Instrumentation: Add failed notifications metric (#18089) 2019-07-24 11:43:24 +02:00
Markus Blaschke
31547597d3 remote_cache: Fix redis connstr parsing (#18204)
* Fix redis connstr parsing

* Don’t log the password
2019-07-23 16:45:04 +03:00
Oleg Gaidarenko
d16fd58bdb
Auth: do not expose disabled user disabled status (#18229)
Fixes #17947
2019-07-23 13:12:55 +03:00
Kyle Brandt
ea0cee4c35
alerting: more specific error when missing threshold (#18221)
fixes #18184
2019-07-22 13:23:33 -04:00
Kyle Brandt
172464e91e
alerting: return err when SetAlertState fails to save to sql (#18216)
fix duplicate alert states when the alert fails to save to the database.
fixes #18176
2019-07-22 07:23:27 -04:00
Leonard Gram
2014549fa5 PhantomJS: Fixes rendering on Debian Buster (#18162)
Closes #17588
2019-07-20 13:03:10 +02:00
Raphael Couto
bc0da1bbfc Plugin: AzureMonitor - Reapply MetricNamespace support (#17282)
* Reapply MetricNamespace support

* Fixing tests

* refactor: move metricnamespace param to backend

* refactor: remove unused function

* azuremonitor: migration for new metric namespace field

* azuremonitor: add template query for metric namespace with a sub

* docs: template queries for azure monitor

Adds new lines for the metricnamespace template function and fixes
some messed up lines
2019-07-20 01:43:52 +02:00
Alexander Zobnin
ccf11fb7a2
SAML: add auth provider label (#18197) 2019-07-19 17:13:29 +03:00
Ryan McKinley
0ca1e90b2e
Plugins: fix previous commit, output "build" property in json 2019-07-19 06:21:39 -07:00
Alexander Zobnin
214195441f
SAML: add metrics (#18194) 2019-07-19 15:30:31 +03:00
Ryan McKinley
3e0625ff3d
Plugins: add build info to plugin metadata (#18164) 2019-07-18 11:52:34 -07:00
Kyle Brandt
7cac393ddc
datasource: testdata - add predicatable csv wave scenario (#18183) 2019-07-18 13:36:22 -04:00
Kyle Brandt
ed099d5ca0
datasource: testdata - add predictable pulse scenario (#18142)
Adds pulse waveform. Is predictable in the sense that the start of the waveform is aligned to epoch time (instead of the start of the query time). This makes a useful signal for manual testing of alerting in the devenv.
2019-07-17 15:48:08 -04:00
Oleg Gaidarenko
d9f01cb822
SQLStore: use bool pointer instead of string (#18111) 2019-07-17 06:24:56 +03:00
Oleg Gaidarenko
75fa1f0207 Metrics: use consistent naming for exported variables (#18134)
* Metrics: remove unused metrics

Metric `M_Grafana_Version` is not used anywhere, nor the mentioned
`M_Grafana_Build_Version`. Seems to be an artefact?

* Metrics: make the naming consistent

* Metrics: add comments to exported vars

* Metrics: use proper naming

Fixes #18110
2019-07-16 16:58:46 +02:00
Oleg Gaidarenko
8e0f091f14
SQLStore: allow to look for is_disabled flag (#18032)
* Add support for `is_disabled` to `CreateUser()`

* Add support for `is_disabled` to `SearchUsers()`
  Had to add it as a `string` type not as `bool`, since if that's property
  is omitted, we would have add it to SQL request, which might be dangerous

* Restructure desctructive tests and add more
2019-07-15 09:14:32 +03:00
Oleg Gaidarenko
09eb9a45ce
Metrics: add LDAP active sync summary metric (#18079) 2019-07-15 08:33:48 +03:00
Kyle Brandt
76d08989f0
provisioning: escape literal '$' with '$$' to avoid interpolation (#18045)
fixes #17986
2019-07-11 07:32:07 -04:00
Anthony Templeton
3680b95b44 Auth: Duplicate API Key Name Handle With Useful HTTP Code (#17905)
* API: Duplicate API Key Name Handle With Useful HTTP Code

* 17447: make changes requested during review

- use dialect.IsUniqueContraintViolation
- change if statement to match others
- return error properly

* Revert "17447: make changes requested during review"

This reverts commit a4a674ea83.

* API: useful http code on duplicate api key error w/ tests

* API: API Key Duplicate Handling

fixed small typo associated with error
2019-07-11 11:20:34 +03:00
Sofia Papagiannaki
f2ad3242be
API: Minor fix for nil pointer when trying to log error during creating new dashboard via the API (#18003)
* Minor fix for nil pointer when trying to log error

* Do not return error if a dashboard is created

Only log the failures

* Do not return error if the folder is created

Only log the failures
2019-07-11 09:45:29 +03:00
Marcus Efraimsson
6a3a2f5f94
CLI: Fix encrypt-datasource-passwords fails with sql error (#18014)
Now handles secure_json_data stored as null in database when
running the encrypt-datasource-passwords migration.

Fixes #17948
2019-07-10 12:28:40 +02:00
Leonard Gram
5d3a60d46e
LDAP: Adds bind before searching LDAP for non-login cases. (#18023) 2019-07-10 12:25:21 +02:00
Alexander Zobnin
5f0a7f43c3
Users: show badges for each auth provider (#17869)
* Users: show badges for each auth provider

* Chore: don't use functions in angular bindings

* Users: minor style changes to labels

* Chore: convert auth labels on the backed side, deduplicate frontend code

* Users: use authLabels everywhere instead of authModule

* User: fix edit user page style

* Users: minor fixes after review
2019-07-10 12:06:51 +03:00
Ryan McKinley
81ff856568
grafana-cli: allow installing plugins from a local zip file (#18021) 2019-07-10 00:40:33 -07:00
Leonard Gram
25506829be
LDAP: Adds back support for single bind. (#17999) 2019-07-09 14:12:17 +02:00
gotjosh
332920954e
SAML: Show SAML login button even if OAuth is disabled (#17993)
* Move the SAML button outside of the oauth div
* Don't attempt to search cookies with an empty name
2019-07-09 10:15:52 +01:00
Sofia Papagiannaki
78ca55f3d7
Fix: Break redirect loop if oauth_auto_login = true and OAuth login fails (#17974)
* Add tests for login view

* Fix OAuth auto login redirect loop

login_error cookie is only set when the OAuth login fails
for some reason. Therefore, the login view should return
immediately if a login_error cookie exists before trying
to login the user using OAuth again.

* Fix test

Use 'index-template' instead of 'index' for testing

* Add some comments
2019-07-09 09:37:24 +03:00
Marcus Efraimsson
962d4daabd
Api: Fix auth tokens returning wrong seenAt value (#17980)
Changes so a non-set seenAt property gets the createdAt value.

Fixes #17953
2019-07-08 14:30:02 +02:00
Oleg Gaidarenko
e2cf7c9698
LDAP: finishing touches (#17945)
* LDAP:Docs: `active_sync_enabled` setting

Mention `active_sync_enabled` setting and enable it by default

* LDAP: move "disableExternalUser" method

Idea behind new design of the LDAP module is to minimise conflation
between other parts of the system, so it would decoupled as much as
possible from stuff like database, HTTP transport and etc.

Following "Do One Thing and Do It Well" Unix philosophy principal, other things
could be better fitted on the consumer side of things.

Which what this commit trying to archive

* LDAP: correct user/admin binding

The second binding was not happening, so if the admin login/password
in LDAP configuration was correct, anyone could had login as anyone using
incorrect password
2019-07-05 17:49:00 +03:00
Leonard Gram
b67905a963
Auth: saml enabled check. (#17960) 2019-07-05 16:39:52 +02:00
Leonard Gram
e574147b1e Auth: SAML login button. (#17932)
* Auth: SAML login button.

* Fixed ts issue
2019-07-05 15:24:52 +02:00
gotjosh
e6b8a1529b
SAML: Configuration defaults, examples and dependencies (#17954)
* Add SAML configuration options

* Add crewjam/saml as a depdency

Needed as part of the enterprise SAML integration.

* Vendor github.com/stretchr/testify/require

The package require implements the same assertions as the `assert` package but stops test execution when a test fails.
2019-07-05 11:27:14 +01:00
Alexander Zobnin
48d5a1bcd3 OAuth: deny login for disabled users (#17957) 2019-07-05 11:35:04 +02:00
Daniel Lee
7e95ded164
AzureMonitor: remove duplicate query logic on the frontend (#17198)
* feat: AzureMonitor implements legend key on backend

To be able to remove the duplicated query logic on the
frontend, the backend code needs to implement alias
patterns for legend keys as well as allowing the default
list of allowed time grains to be overridden. Some metrics
do not support all the time grains and the auto timegrain
calculation can be incorrect if the list is not overridden.

* feat: AzureMonitor - removes duplicate query logic on frontend

* AzureMonitor small refactoring

Extracted method and tidied up the auto time grain
code.

* azuremonitor: support for auto time grains for alerting

Converts allowed timegrains into ms and saves in dashboard json.
This makes queries for alerting with an auto time grain work in
the same way as the frontend.

* chore: typings -> implicitAny count down to 3413

* azuremonitor: add more typings
2019-07-04 22:47:24 +02:00
Oleg Gaidarenko
444c4d5999
LDAP: Divide the requests (#17885)
* LDAP: Divide the requests

Active Directory does indeed have a limitation with 1000 results
per search (default of course).

However, that limitation can be workaround with the pagination search feature,
meaning `pagination` number is how many times LDAP compatible server will be
requested by the client with specified amount of users (like 1000). That feature
already embeded with LDAP compatible client (including our `go-ldap`).

But slapd server has by default stricter settings. First, limitation is not 1000
but 500, second, pagination workaround presumably (information about it a bit
scarce and I still not sure on some of the details from my own testing)
cannot be workaround with pagination feature.

See
https://www.openldap.org/doc/admin24/limits.html
https://serverfault.com/questions/328671/paging-using-ldapsearch
hashicorp/vault#4162 - not sure why they were hitting the limit in
the first place, since `go-ldap` doesn't have one by default.

But, given all that, for me `ldapsearch` command with same request
as with `go-ldap` still returns more then 500 results, it can even return
as much as 10500 items (probably more).

So either there is some differences with implementation of the LDAP search
between `go-ldap` module and `ldapsearch` or I am missing a step :/.

In the wild (see serverfault link), apparently, people still hitting that
limitation even with `ldapsearch`, so it still seems to be an issue.

But, nevertheless, I'm still confused by this incoherence.

To workaround it, I divide the request by no more then
500 items per search
2019-07-03 17:39:54 +03:00
Alexander Zobnin
3d848d0fdf
Teams: show proper label for each auth provider (#17860)
* Teams: show proper label for each auth provider

Teams: don't sore AuthModule in team_member table, use JOIN to get it instead

* Teams: fix AddTeamMember after last changes

* Teams: add more auth provider labels

* Teams: show external sync badge if LDAP is not enabled

* Teams: tests for getting auth module
2019-07-03 16:52:10 +03:00
Anthony Templeton
0d2be0a7ed Logging: Login and Logout logging actions (#17760) (#17883) 2019-07-03 15:16:00 +02:00