diff --git a/README.md b/README.md index 89b4892..c4d4aa5 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ In contrast to [ACL](https://en.wikipedia.org/wiki/Access_control_list) and [RBA you get fine-grained access control with the ability to answer questions in complex environments such as multi-tenant or distributed applications and large organizations. Ladon is inspired by [AWS IAM Policies](http://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html). -Ladon ships with storage adapters for SQL (officially supported: MySQL, PostgreSQL) and in-memory. +Ladon ships with storage adapters for SQL (officially supported: MySQL 5.5+, PostgreSQL 9.2+) and in-memory. --- @@ -26,7 +26,7 @@ ORY builds solutions for better internet security and accessibility. We have a c * **[Hydra](https://github.com/ory/hydra)**, a security-first open source OAuth2 and OpenID Connect server for new and existing infrastructures that uses Ladon for access control. * **[ORY Editor](https://github.com/ory/editor)**, an extensible, modern WYSI editor for the web written in React. -* **[Fosite](https://github.com/ory/fosite)**, an extensible security first OAuth 2.0 and OpenID Connect SDK for Go. +* **[Fosite](https://github.com/ory/fosite)**, an extensible security first OAuth 2.0 and OpenID Connect SDK for Go. * **[Dockertest](https://github.com/ory/dockertest)**: Write better integration tests with dockertest! --- diff --git a/integration/integration.go b/integration/integration.go index 56c2575..b81760d 100644 --- a/integration/integration.go +++ b/integration/integration.go @@ -32,7 +32,7 @@ func ConnectToMySQL() *sqlx.DB { log.Fatalf("Could not connect to docker: %s", err) } - resource, err := pool.Run("mysql", "5.7", []string{"MYSQL_ROOT_PASSWORD=secret"}) + resource, err := pool.Run("mysql", "5.6", []string{"MYSQL_ROOT_PASSWORD=secret"}) if err != nil { log.Fatalf("Could not start resource: %s", err) } @@ -60,7 +60,7 @@ func ConnectToPostgres(database string) *sqlx.DB { log.Fatalf("Could not connect to docker: %s", err) } - resource, err := pool.Run("postgres", "9.6", []string{"POSTGRES_PASSWORD=secret", "POSTGRES_DB=" + database}) + resource, err := pool.Run("postgres", "9.2", []string{"POSTGRES_PASSWORD=secret", "POSTGRES_DB=" + database}) if err != nil { log.Fatalf("Could not start resource: %s", err) } diff --git a/manager/sql/manager_sql.go b/manager/sql/manager_sql.go index 1a67c1c..a5cb9b7 100644 --- a/manager/sql/manager_sql.go +++ b/manager/sql/manager_sql.go @@ -190,13 +190,20 @@ func (s *SQLManager) Create(policy Policy) (err error) { } switch s.db.DriverName() { - case "postgres", "pgx", "mysql": + case "postgres", "pgx": if _, err = tx.Exec(s.db.Rebind("INSERT INTO ladon_policy (id, description, effect, conditions) SELECT ?, ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM ladon_policy WHERE id = ?)"), policy.GetID(), policy.GetDescription(), policy.GetEffect(), conditions, policy.GetID()); err != nil { if err := tx.Rollback(); err != nil { return errors.WithStack(err) } return errors.WithStack(err) } + case "mysql": + if _, err = tx.Exec(s.db.Rebind("INSERT IGNORE INTO ladon_policy (id, description, effect, conditions) VALUES (?, ?, ?, ?)"), policy.GetID(), policy.GetDescription(), policy.GetEffect(), conditions); err != nil { + if err := tx.Rollback(); err != nil { + return errors.WithStack(err) + } + return errors.WithStack(err) + } default: if err := tx.Rollback(); err != nil { return errors.WithStack(err) @@ -225,7 +232,7 @@ func (s *SQLManager) Create(policy Policy) (err error) { } switch s.db.DriverName() { - case "postgres", "pgx", "mysql": + case "postgres", "pgx": if _, err := tx.Exec(s.db.Rebind(fmt.Sprintf("INSERT INTO ladon_%s (id, template, compiled, has_regex) SELECT ?, ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM ladon_%[1]s WHERE id = ?)", v.t)), id, template, compiled.String(), strings.Index(template, string(policy.GetStartDelimiter())) > -1, id); err != nil { if err := tx.Rollback(); err != nil { return errors.WithStack(err) @@ -240,6 +247,22 @@ func (s *SQLManager) Create(policy Policy) (err error) { return errors.WithStack(err) } break + + case "mysql": + if _, err := tx.Exec(s.db.Rebind(fmt.Sprintf("INSERT IGNORE INTO ladon_%s (id, template, compiled, has_regex) VALUES (?, ?, ?, ?)", v.t)), id, template, compiled.String(), strings.Index(template, string(policy.GetStartDelimiter())) > -1); err != nil { + if err := tx.Rollback(); err != nil { + return errors.WithStack(err) + } + return errors.WithStack(err) + } + + if _, err := tx.Exec(s.db.Rebind(fmt.Sprintf("INSERT IGNORE INTO ladon_policy_%s_rel (policy, %s) VALUES (?, ?)", v.t, v.t)), policy.GetID(), id); err != nil { + if err := tx.Rollback(); err != nil { + return errors.WithStack(err) + } + return errors.WithStack(err) + } + break default: if err := tx.Rollback(); err != nil { return errors.WithStack(err)