Auth: Attach external session info to Grafana session (#93849)
* initial from poc changes * wip * Remove public external session service * Update swagger * Fix merge * Cleanup * Add backgroud service for cleanup * Add auth_module to user_external_session * Add tests for token revocation functions * Add secret migration capabilities for user_external_session fields * Cleanup, refactor to address feedback * Fix test
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package externalsession
|
||||
|
||||
import "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
|
||||
func AddMigration(mg *migrator.Migrator) {
|
||||
externalSessionV1 := migrator.Table{
|
||||
Name: "user_external_session",
|
||||
Columns: []*migrator.Column{
|
||||
{Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
|
||||
{Name: "user_auth_id", Type: migrator.DB_BigInt, Nullable: false},
|
||||
{Name: "user_id", Type: migrator.DB_BigInt, Nullable: false},
|
||||
{Name: "auth_module", Type: migrator.DB_NVarchar, Length: 190, Nullable: false},
|
||||
{Name: "access_token", Type: migrator.DB_Text, Nullable: true},
|
||||
{Name: "id_token", Type: migrator.DB_Text, Nullable: true},
|
||||
{Name: "refresh_token", Type: migrator.DB_Text, Nullable: true},
|
||||
{Name: "session_id", Type: migrator.DB_NVarchar, Length: 255, Nullable: true},
|
||||
{Name: "session_id_hash", Type: migrator.DB_Char, Length: 44, Nullable: true},
|
||||
{Name: "name_id", Type: migrator.DB_NVarchar, Length: 255, Nullable: true},
|
||||
{Name: "name_id_hash", Type: migrator.DB_Char, Length: 44, Nullable: true},
|
||||
{Name: "expires_at", Type: migrator.DB_DateTime, Nullable: true},
|
||||
{Name: "created_at", Type: migrator.DB_DateTime, Nullable: false},
|
||||
},
|
||||
Indices: []*migrator.Index{
|
||||
{Cols: []string{"user_id"}},
|
||||
{Cols: []string{"session_id_hash"}},
|
||||
{Cols: []string{"name_id_hash"}},
|
||||
},
|
||||
}
|
||||
|
||||
mg.AddMigration("create user_external_session table", migrator.NewAddTableMigration(externalSessionV1))
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrations/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrations/anonservice"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrations/externalsession"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrations/signingkeys"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrations/ssosettings"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrations/ualert"
|
||||
@@ -135,6 +136,8 @@ func (oss *OSSMigrations) AddMigration(mg *Migrator) {
|
||||
accesscontrol.AddOrphanedMigrations(mg)
|
||||
|
||||
accesscontrol.AddActionSetPermissionsMigrator(mg)
|
||||
|
||||
externalsession.AddMigration(mg)
|
||||
}
|
||||
|
||||
func addStarMigrations(mg *Migrator) {
|
||||
|
||||
@@ -48,4 +48,8 @@ func addUserAuthTokenMigrations(mg *Migrator) {
|
||||
mg.AddMigration("add index user_auth_token.revoked_at", NewAddIndexMigration(userAuthTokenV1, &Index{
|
||||
Cols: []string{"revoked_at"},
|
||||
}))
|
||||
|
||||
mg.AddMigration("add external_session_id to user_auth_token", NewAddColumnMigration(userAuthTokenV1, &Column{
|
||||
Name: "external_session_id", Type: DB_BigInt, Nullable: true,
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user