From a6bd2c73a01fe126429649f3538166b2dc50f4de Mon Sep 17 00:00:00 2001 From: bergquist Date: Fri, 1 Feb 2019 11:47:21 +0100 Subject: [PATCH 01/10] introduce samesite setting for login cookie ref #15067 --- conf/defaults.ini | 3 +++ conf/sample.ini | 3 +++ pkg/services/auth/auth_token.go | 1 + pkg/setting/setting.go | 16 ++++++++++++++++ 4 files changed, 23 insertions(+) diff --git a/conf/defaults.ini b/conf/defaults.ini index 788112ae67e..d021d342fbf 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -113,6 +113,9 @@ cache_mode = private # Login cookie name cookie_name = grafana_session +# Login cookie same site setting. defaults to `lax`. can be set to "lax", "strict" and "none" +cookie_samesite = lax + # How many days an session can be unused before we inactivate it login_remember_days = 7 diff --git a/conf/sample.ini b/conf/sample.ini index 89880106345..ef677320686 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -109,6 +109,9 @@ log_queries = # Login cookie name ;cookie_name = grafana_session +# Login cookie same site setting. defaults to `lax`. can be set to "lax", "strict" and "none" +;cookie_samesite = lax + # How many days an session can be unused before we inactivate it ;login_remember_days = 7 diff --git a/pkg/services/auth/auth_token.go b/pkg/services/auth/auth_token.go index db4d9d18624..98687f2013d 100644 --- a/pkg/services/auth/auth_token.go +++ b/pkg/services/auth/auth_token.go @@ -96,6 +96,7 @@ func (s *UserAuthTokenServiceImpl) writeSessionCookie(ctx *models.ReqContext, va Path: setting.AppSubUrl + "/", Secure: s.Cfg.SecurityHTTPSCookies, MaxAge: maxAge, + SameSite: s.Cfg.LoginCookieSameSite, } http.SetCookie(ctx.Resp, &cookie) diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index cf486a228ab..c3c78d10fec 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -6,6 +6,7 @@ package setting import ( "bytes" "fmt" + "net/http" "net/url" "os" "path" @@ -227,6 +228,7 @@ type Cfg struct { LoginCookieMaxDays int LoginCookieRotation int LoginDeleteExpiredTokensAfterDays int + LoginCookieSameSite http.SameSite SecurityHTTPSCookies bool } @@ -557,6 +559,20 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error { cfg.LoginCookieName = login.Key("cookie_name").MustString("grafana_session") cfg.LoginCookieMaxDays = login.Key("login_remember_days").MustInt(7) cfg.LoginDeleteExpiredTokensAfterDays = login.Key("delete_expired_token_after_days").MustInt(30) + + samesiteString := login.Key("cookie_samesite").MustString("lax") + validSameSiteValues := map[string]http.SameSite{ + "lax": http.SameSiteLaxMode, + "strict": http.SameSiteStrictMode, + "none": http.SameSiteDefaultMode, + } + + if samesite, ok := validSameSiteValues[samesiteString]; ok { + cfg.LoginCookieSameSite = samesite + } else { + cfg.LoginCookieSameSite = http.SameSiteLaxMode + } + cfg.LoginCookieRotation = login.Key("rotate_token_minutes").MustInt(10) if cfg.LoginCookieRotation < 2 { cfg.LoginCookieRotation = 2 From ab1ae1b2a7d019b27739f24e5038b2a2ca632ffd Mon Sep 17 00:00:00 2001 From: Alexander Wellbrock Date: Fri, 1 Feb 2019 12:51:40 +0100 Subject: [PATCH 02/10] Clearify the Run from master instructions Especially for new developers to the go and yarn ecosystems this readme part is quite confusing. --- README.md | 52 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 3df6a383e05..658f1e34257 100644 --- a/README.md +++ b/README.md @@ -25,49 +25,71 @@ the latest master builds [here](https://grafana.com/grafana/download) ### Dependencies - Go (Latest Stable) + - bra [`go get github.com/Unknwon/bra`] - Node.js LTS + - yarn [`npm install -g yarn`] + +### Get the project + +**The project located in the go-path will be your working directory.** -### Building the backend ```bash go get github.com/grafana/grafana cd $GOPATH/src/github.com/grafana/grafana +``` + +### Building + +#### The backend + +```bash go run build.go setup go run build.go build ``` -### Building frontend assets +#### Frontend assets -For this you need Node.js (LTS version). +*For this you need Node.js (LTS version).* -To build the assets, rebuild on file change, and serve them by Grafana's webserver (http://localhost:3000): ```bash -npm install -g yarn yarn install --pure-lockfile +``` + +### Run and rebuild on source change + +#### Backend + +To run the backend and rebuild on source change: + +```bash +$GOPATH/bin/bra run +``` + +#### Frontend + +Rebuild on file change, and serve them by Grafana's webserver (http://localhost:3000): + +```bash yarn watch ``` Build the assets, rebuild on file change with Hot Module Replacement (HMR), and serve them by webpack-dev-server (http://localhost:3333): + ```bash yarn start # OR set a theme env GRAFANA_THEME=light yarn start ``` -Note: HMR for Angular is not supported. If you edit files in the Angular part of the app, the whole page will reload. -Run tests -```bash -yarn jest -``` +*Note: HMR for Angular is not supported. If you edit files in the Angular part of the app, the whole page will reload.* -### Recompile backend on source change +Run tests and rebuild on source change: -To rebuild on source change. ```bash -go get github.com/Unknwon/bra -bra run +yarn jest ``` -Open grafana in your browser (default: `http://localhost:3000`) and login with admin user (default: `user/pass = admin/admin`). +**Open grafana in your browser (default: e.g. `http://localhost:3000`) and login with admin user (default: `user/pass = admin/admin`).** ### Building a Docker image From 025d37e9a2f2f886e6b6e2f62dfb93d32379bee6 Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Fri, 1 Feb 2019 14:19:53 +0100 Subject: [PATCH 03/10] add button in header --- .../PanelOptionsGroup/PanelOptionsGroup.tsx | 34 ++++++++++++------- .../PanelOptionsGroup/_PanelOptionsGroup.scss | 15 +++++++- .../ValueMappingsEditor.tsx | 14 ++------ 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/packages/grafana-ui/src/components/PanelOptionsGroup/PanelOptionsGroup.tsx b/packages/grafana-ui/src/components/PanelOptionsGroup/PanelOptionsGroup.tsx index 7ce4b8335ff..5378147c741 100644 --- a/packages/grafana-ui/src/components/PanelOptionsGroup/PanelOptionsGroup.tsx +++ b/packages/grafana-ui/src/components/PanelOptionsGroup/PanelOptionsGroup.tsx @@ -1,26 +1,36 @@ // Libraries -import React, { SFC } from 'react'; +import React, { FunctionComponent } from 'react'; interface Props { title?: string; onClose?: () => void; - children: JSX.Element | JSX.Element[]; + children: JSX.Element | JSX.Element[] | boolean; + onAdd?: () => void; } -export const PanelOptionsGroup: SFC = props => { +export const PanelOptionsGroup: FunctionComponent = props => { return (
- {props.title && ( -
- {props.title} - {props.onClose && ( - - )} + {props.onAdd ? ( +
+
+ +
+ {props.title}
+ ) : ( + props.title && ( +
+ {props.title} + {props.onClose && ( + + )} +
+ ) )} -
{props.children}
+ {props.children &&
{props.children}
}
); }; diff --git a/packages/grafana-ui/src/components/PanelOptionsGroup/_PanelOptionsGroup.scss b/packages/grafana-ui/src/components/PanelOptionsGroup/_PanelOptionsGroup.scss index cfc832afa98..34881a72743 100644 --- a/packages/grafana-ui/src/components/PanelOptionsGroup/_PanelOptionsGroup.scss +++ b/packages/grafana-ui/src/components/PanelOptionsGroup/_PanelOptionsGroup.scss @@ -11,13 +11,26 @@ background: $panel-options-group-header-bg; position: relative; border-radius: $border-radius $border-radius 0 0; + display: flex; .btn { position: absolute; right: 0; - top: 0px; + top: 0; } } +.panel-options-group__add { + background-color: $btn-success-bg; + border-radius: 50px; + width: 20px; + height: 20px; + display: flex; + align-items: center; + justify-content: center; +} +.panel-options-group__title { + margin-left: 8px; +} .panel-options-group__body { padding: 20px; diff --git a/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditor.tsx b/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditor.tsx index ca0a6e71f4a..88035087a9a 100644 --- a/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditor.tsx +++ b/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditor.tsx @@ -1,8 +1,8 @@ import React, { PureComponent } from 'react'; import MappingRow from './MappingRow'; -import { MappingType, ValueMapping } from '../../types/panel'; -import { PanelOptionsGroup } from '../PanelOptionsGroup/PanelOptionsGroup'; +import { MappingType, ValueMapping } from '../../types'; +import { PanelOptionsGroup } from '..'; export interface Props { valueMappings: ValueMapping[]; @@ -81,8 +81,7 @@ export class ValueMappingsEditor extends PureComponent { const { valueMappings } = this.state; return ( - -
+ {valueMappings.length > 0 && valueMappings.map((valueMapping, index) => ( { removeValueMapping={() => this.onRemoveMapping(valueMapping.id)} /> ))} -
-
-
- -
-
Add mapping
-
); } From 609129c039e2de5b38aa11f37af1160a35a5e27d Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Fri, 1 Feb 2019 14:23:03 +0100 Subject: [PATCH 04/10] fixing test --- .../ValueMappingsEditor.test.tsx | 2 +- .../ValueMappingsEditor.test.tsx.snap | 76 +++++++------------ 2 files changed, 30 insertions(+), 48 deletions(-) diff --git a/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditor.test.tsx b/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditor.test.tsx index bbad3e5a7ca..caa09c9e5ff 100644 --- a/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditor.test.tsx +++ b/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditor.test.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { shallow } from 'enzyme'; import { ValueMappingsEditor, Props } from './ValueMappingsEditor'; -import { MappingType } from '../../types/panel'; +import { MappingType } from '../../types'; const setup = (propOverrides?: object) => { const props: Props = { diff --git a/packages/grafana-ui/src/components/ValueMappingsEditor/__snapshots__/ValueMappingsEditor.test.tsx.snap b/packages/grafana-ui/src/components/ValueMappingsEditor/__snapshots__/ValueMappingsEditor.test.tsx.snap index 8a465ff88df..7f6a70bd926 100644 --- a/packages/grafana-ui/src/components/ValueMappingsEditor/__snapshots__/ValueMappingsEditor.test.tsx.snap +++ b/packages/grafana-ui/src/components/ValueMappingsEditor/__snapshots__/ValueMappingsEditor.test.tsx.snap @@ -2,55 +2,37 @@ exports[`Render should render component 1`] = ` -
- - + -
-
-
- -
-
- Add mapping -
-
+ } + />
`; From 4b03e7c31f85706d2b0075d755afac1a31c66f50 Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Fri, 1 Feb 2019 15:03:19 +0100 Subject: [PATCH 05/10] setting margin on label --- public/app/features/datasources/DataSourcesListItem.tsx | 4 ++-- .../__snapshots__/DataSourcesListItem.test.tsx.snap | 1 + public/sass/components/_cards.scss | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/public/app/features/datasources/DataSourcesListItem.tsx b/public/app/features/datasources/DataSourcesListItem.tsx index 157e9447852..d0ff69a66ee 100644 --- a/public/app/features/datasources/DataSourcesListItem.tsx +++ b/public/app/features/datasources/DataSourcesListItem.tsx @@ -16,12 +16,12 @@ export class DataSourcesListItem extends PureComponent {
- + {dataSource.name}
{dataSource.name} - {dataSource.isDefault && default} + {dataSource.isDefault && default}
{dataSource.url}
diff --git a/public/app/features/datasources/__snapshots__/DataSourcesListItem.test.tsx.snap b/public/app/features/datasources/__snapshots__/DataSourcesListItem.test.tsx.snap index a424276cf32..3ab1b1d53aa 100644 --- a/public/app/features/datasources/__snapshots__/DataSourcesListItem.test.tsx.snap +++ b/public/app/features/datasources/__snapshots__/DataSourcesListItem.test.tsx.snap @@ -24,6 +24,7 @@ exports[`Render should render component 1`] = ` className="card-item-figure" > gdev-cloudwatch diff --git a/public/sass/components/_cards.scss b/public/sass/components/_cards.scss index f39be84ec04..569b16279dd 100644 --- a/public/sass/components/_cards.scss +++ b/public/sass/components/_cards.scss @@ -109,6 +109,10 @@ width: 100%; } +.card-item-label { + margin-left: 8px; +} + .card-item-sub-name { color: $text-color-weak; overflow: hidden; From 3be1deea4478e51bb8d6a3bd3a88f7e4b7077995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 1 Feb 2019 15:19:18 +0100 Subject: [PATCH 06/10] Made some style tweaks --- .../PanelOptionsGroup/PanelOptionsGroup.tsx | 14 ++++---- .../PanelOptionsGroup/_PanelOptionsGroup.scss | 32 ++++++++++++++++--- .../ThresholdsEditor/_ThresholdsEditor.scss | 12 +++---- .../ValueMappingsEditor.tsx | 2 +- 4 files changed, 43 insertions(+), 17 deletions(-) diff --git a/packages/grafana-ui/src/components/PanelOptionsGroup/PanelOptionsGroup.tsx b/packages/grafana-ui/src/components/PanelOptionsGroup/PanelOptionsGroup.tsx index 5378147c741..8516760d6f3 100644 --- a/packages/grafana-ui/src/components/PanelOptionsGroup/PanelOptionsGroup.tsx +++ b/packages/grafana-ui/src/components/PanelOptionsGroup/PanelOptionsGroup.tsx @@ -12,16 +12,18 @@ export const PanelOptionsGroup: FunctionComponent = props => { return (
{props.onAdd ? ( -
-
- -
- {props.title} +
+
) : ( props.title && (
- {props.title} + {props.title} {props.onClose && (