Skip to content

Commit

Permalink
Add implicit_assignment field to the okta_app_saml resource (#703)
Browse files Browse the repository at this point in the history
Co-authored-by: Bogdan Prodan <bogdan.prodan@okta.com>
  • Loading branch information
ashwini-desai and bogdanprodan-okta authored Oct 11, 2021
1 parent 09dc8b5 commit 9bbad86
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 7 deletions.
18 changes: 18 additions & 0 deletions examples/okta_app_saml/federation_broker_off.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "okta_app_saml" "test" {
label = "testAcc_replace_with_uuid"
sso_url = "http://google.com"
recipient = "http://here.com"
destination = "http://its-about-the-journey.com"
audience = "http://audience.com"
subject_name_id_template = "$${user.userName}"
subject_name_id_format = "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
response_signed = true
signature_algorithm = "RSA_SHA256"
digest_algorithm = "SHA256"
honor_force_authn = false
authn_context_class_ref = "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"
single_logout_issuer = "https://dunshire.okta.com"
single_logout_url = "https://dunshire.okta.com/logout"
single_logout_certificate = "MIIFnDCCA4QCCQDBSLbiON2T1zANBgkqhkiG9w0BAQsFADCBjzELMAkGA1UEBhMCVVMxDjAMBgNV\r\nBAgMBU1haW5lMRAwDgYDVQQHDAdDYXJpYm91MRcwFQYDVQQKDA5Tbm93bWFrZXJzIEluYzEUMBIG\r\nA1UECwwLRW5naW5lZXJpbmcxDTALBgNVBAMMBFNub3cxIDAeBgkqhkiG9w0BCQEWEWVtYWlsQGV4\r\nYW1wbGUuY29tMB4XDTIwMTIwMzIyNDY0M1oXDTMwMTIwMTIyNDY0M1owgY8xCzAJBgNVBAYTAlVT\r\nMQ4wDAYDVQQIDAVNYWluZTEQMA4GA1UEBwwHQ2FyaWJvdTEXMBUGA1UECgwOU25vd21ha2VycyBJ\r\nbmMxFDASBgNVBAsMC0VuZ2luZWVyaW5nMQ0wCwYDVQQDDARTbm93MSAwHgYJKoZIhvcNAQkBF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AZUCGBTvezNzaetGzTUjjl/g1tcVYij\r\nltH9ZOQBPlUMI88lxUxqgRTerpPmAJH00CACx4JFiZrweLM1trZyy06wNDQgLrqHr3EOagBF/O2h\r\nhfTehNdVr6iq3YhKWBo4/+RL0RCzHMh4u86VbDDnDn4Y6HzLuyIAtBFoikoKM6UHTOa0Pqv2bBr5\r\nwbkRkVUxl9yJJw/HmTCdfnsM9dTOJUKzEglnGF2184Gg+qJDZB6fSf0EAO1F6sTqiSswl+uHQZiy\r\nDaZzyU7Gg5seKOZ20zTRaX3Ihj9Zij/ORnrARE7eM/usKMECp+7syUwAUKxDCZkGiUdskmOhhBGL\r\nJtbyK3F2UvoJoLsm3pIcvMak9KwMjSTGJB47ABUP1+w+zGcNk0D5Co3IJ6QekiLfWJyQ+kKsWLKt\r\nzOYQQatrnBagM7MI2/T4\r\n"
implicit_assignment = false
}
18 changes: 18 additions & 0 deletions examples/okta_app_saml/federation_broker_on.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "okta_app_saml" "test" {
label = "testAcc_replace_with_uuid"
sso_url = "http://google.com"
recipient = "http://here.com"
destination = "http://its-about-the-journey.com"
audience = "http://audience.com"
subject_name_id_template = "$${user.userName}"
subject_name_id_format = "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
response_signed = true
signature_algorithm = "RSA_SHA256"
digest_algorithm = "SHA256"
honor_force_authn = false
authn_context_class_ref = "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"
single_logout_issuer = "https://dunshire.okta.com"
single_logout_url = "https://dunshire.okta.com/logout"
single_logout_certificate = "MIIFnDCCA4QCCQDBSLbiON2T1zANBgkqhkiG9w0BAQsFADCBjzELMAkGA1UEBhMCVVMxDjAMBgNV\r\nBAgMBU1haW5lMRAwDgYDVQQHDAdDYXJpYm91MRcwFQYDVQQKDA5Tbm93bWFrZXJzIEluYzEUMBIG\r\nA1UECwwLRW5naW5lZXJpbmcxDTALBgNVBAMMBFNub3cx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KoZIhvcNAQELBQADggIBADofEC1SvG8qa7pmKCjB/E9Sxhk3mvUO9Gq43xzwVb721Ng3VYf4vGU3\r\nwLUwJeLt0wggnj26NJweN5T3q9T8UMxZhHSWvttEU3+S1nArRB0beti716HSlOCDx4wTmBu/D1MG\r\nt/kZYFJw+zuzvAcbYct2pK69AQhD8xAIbQvqADJI7cCK3yRry+aWtppc58P81KYabUlCfFXfhJ9E\r\nP72ffN4jVHpX3lxxYh7FKAdiKbY2FYzjsc7RdgKI1R3iAAZUCGBTvezNzaetGzTUjjl/g1tcVYij\r\nltH9ZOQBPlUMI88lxUxqgRTerpPmAJH00CACx4JFiZrweLM1trZyy06wNDQgLrqHr3EOagBF/O2h\r\nhfTehNdVr6iq3YhKWBo4/+RL0RCzHMh4u86VbDDnDn4Y6HzLuyIAtBFoikoKM6UHTOa0Pqv2bBr5\r\nwbkRkVUxl9yJJw/HmTCdfnsM9dTOJUKzEglnGF2184Gg+qJDZB6fSf0EAO1F6sTqiSswl+uHQZiy\r\nDaZzyU7Gg5seKOZ20zTRaX3Ihj9Zij/ORnrARE7eM/usKMECp+7syUwAUKxDCZkGiUdskmOhhBGL\r\nJtbyK3F2UvoJoLsm3pIcvMak9KwMjSTGJB47ABUP1+w+zGcNk0D5Co3IJ6QekiLfWJyQ+kKsWLKt\r\nzOYQQatrnBagM7MI2/T4\r\n"
implicit_assignment = true
}
2 changes: 2 additions & 0 deletions okta/resource_okta_app_oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ func resourceAppOAuthRead(ctx context.Context, d *schema.ResourceData, m interfa
_ = d.Set("logo_url", linksValue(app.Links, "logo", "href"))
if app.Settings.ImplicitAssignment != nil {
_ = d.Set("implicit_assignment", *app.Settings.ImplicitAssignment)
} else {
_ = d.Set("implicit_assignment", false)
}
// If this is ever changed omit it.
if d.Get("omit_secret").(bool) {
Expand Down
41 changes: 34 additions & 7 deletions okta/resource_okta_app_saml.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ func resourceAppSaml() *schema.Resource {
Default: false,
Description: "Do not display application icon to users",
},
"implicit_assignment": {
Type: schema.TypeBool,
Optional: true,
Description: "*Early Access Property*. Enable Federation Broker Mode.",
ConflictsWith: []string{"groups", "users"},
},
"default_relay_state": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -369,6 +375,14 @@ func resourceAppSamlCreate(ctx context.Context, d *schema.ResourceData, m interf
}
// Make sure to track in terraform prior to the creation of cert in case there is an error.
d.SetId(app.Id)
// When the implicit_assignment is turned on, calls to the user/group assignments will error with a bad request
// So Skip setting assignments while this is on
if !d.Get("implicit_assignment").(bool) {
err = handleAppGroupsAndUsers(ctx, app.Id, d, m)
if err != nil {
return diag.Errorf("failed to handle groups and users for SAML application: %v", err)
}
}
err = tryCreateCertificate(ctx, d, m, app.Id)
if err != nil {
return diag.Errorf("failed to create new certificate for SAML application: %v", err)
Expand Down Expand Up @@ -412,6 +426,11 @@ func resourceAppSamlRead(ctx context.Context, d *schema.ResourceData, m interfac
_ = d.Set("user_name_template_suffix", app.Credentials.UserNameTemplate.Suffix)
_ = d.Set("preconfigured_app", app.Name)
_ = d.Set("logo_url", linksValue(app.Links, "logo", "href"))
if app.Settings.ImplicitAssignment != nil {
_ = d.Set("implicit_assignment", *app.Settings.ImplicitAssignment)
} else {
_ = d.Set("implicit_assignment", false)
}
if app.Credentials.Signing.Kid != "" && app.Status != statusInactive {
keyID := app.Credentials.Signing.Kid
_ = d.Set("key_id", keyID)
Expand Down Expand Up @@ -440,9 +459,12 @@ func resourceAppSamlRead(ctx context.Context, d *schema.ResourceData, m interfac
} else {
_ = d.Set("saml_version", saml20)
}
err = syncGroupsAndUsers(ctx, app.Id, d, m)
if err != nil {
return diag.Errorf("failed to sync groups and users for SAML application: %v", err)
// When the implicit_assignment is turned on, calls to the user/group assignments will error with a bad request
// So Skip setting assignments while this is on
if !d.Get("implicit_assignment").(bool) {
if err = syncGroupsAndUsers(ctx, app.Id, d, m); err != nil {
return diag.Errorf("failed to sync groups and users for OAuth application: %v", err)
}
}
return nil
}
Expand Down Expand Up @@ -471,9 +493,13 @@ func resourceAppSamlUpdate(ctx context.Context, d *schema.ResourceData, m interf
return diag.Errorf("failed to create new certificate for SAML application: %v", err)
}
}
err = handleAppGroupsAndUsers(ctx, app.Id, d, m)
if err != nil {
return diag.Errorf("failed to handle groups and users for SAML application: %v", err)
// When the implicit_assignment is turned on, calls to the user/group assignments will error with a bad request
// So Skip setting assignments while this is on
if !d.Get("implicit_assignment").(bool) {
err = handleAppGroupsAndUsers(ctx, app.Id, d, m)
if err != nil {
return diag.Errorf("failed to handle groups and users for OAuth application: %v", err)
}
}
if d.HasChange("logo") {
err = handleAppLogo(ctx, d, m, app.Id, app.Links)
Expand Down Expand Up @@ -521,7 +547,8 @@ func buildSamlApp(d *schema.ResourceData) (*okta.SamlApplication, error) {

honorForce := d.Get("honor_force_authn").(bool)
app.Settings = &okta.SamlApplicationSettings{
Notes: buildAppNotes(d),
ImplicitAssignment: boolPtr(d.Get("implicit_assignment").(bool)),
Notes: buildAppNotes(d),
}
app.Visibility = buildAppVisibility(d)
app.Accessibility = buildAppAccessibility(d)
Expand Down
41 changes: 41 additions & 0 deletions okta/resource_okta_app_saml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,47 @@ func TestAccAppSaml_inlineHook(t *testing.T) {
})
}

// Tests creation of service app and updates it to turn on federated broker
func TestAccAppSaml_federationBroker(t *testing.T) {
// TODO: This is an "Early Access Feature" and needs to be enabled by Okta
// Skipping for now assuming that the okta account doesn't have this feature enabled.
// If this feature is enabled or Okta releases this to all this test should be enabled.
// SEE https://help.okta.com/en/prod/Content/Topics/Apps/apps-fbm-enable.htm
t.Skip("This is an 'Early Access Feature' and needs to be enabled by Okta, skipping this test as it fails when this feature is not available")

ri := acctest.RandInt()
mgr := newFixtureManager(appSaml)
config := mgr.GetFixtures("federation_broker_off.tf", ri, t)
updatedConfig := mgr.GetFixtures("federation_broker_on.tf", ri, t)
resourceName := fmt.Sprintf("%s.test", appSaml)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProvidersFactories,
CheckDestroy: createCheckResourceDestroy(appOAuth, createDoesAppExist(okta.NewOpenIdConnectApplication())),
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
ensureResourceExists(resourceName, createDoesAppExist(okta.NewOpenIdConnectApplication())),
resource.TestCheckResourceAttr(resourceName, "label", buildResourceName(ri)),
resource.TestCheckResourceAttr(resourceName, "status", "ACTIVE"),
resource.TestCheckResourceAttr(resourceName, "implicit_assignment", "false"),
),
},
{
Config: updatedConfig,
Check: resource.ComposeTestCheckFunc(
ensureResourceExists(resourceName, createDoesAppExist(okta.NewOpenIdConnectApplication())),
resource.TestCheckResourceAttr(resourceName, "label", buildResourceName(ri)),
resource.TestCheckResourceAttr(resourceName, "status", "ACTIVE"),
resource.TestCheckResourceAttr(resourceName, "implicit_assignment", "true"),
),
},
},
})
}

func buildTestSamlConfigMissingFields(rInt int) string {
name := buildResourceName(rInt)

Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/app_saml.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ The following arguments are supported:

- `hide_web` - (Optional) Do not display application icon to users

- `implicit_assignment` - (Optional) *Early Access Property*. Enables [Federation Broker Mode]( https://help.okta.com/en/prod/Content/Topics/Apps/apps-fbm-enable.htm). When this mode is enabled, `users` and `groups` arguments are ignored.

- `default_relay_state` - (Optional) Identifies a specific application resource in an IDP initiated SSO scenario.

- `sso_url` - (Optional) Single Sign-on Url.
Expand Down

0 comments on commit 9bbad86

Please sign in to comment.