Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for user/pass fortigate auth #250

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion fortios/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ type Config struct {
CaCert string
ClientCert string
ClientKey string

PassAuth string
Username string
Passwd string
}

// FortiClient contains the basic FortiOS SDK connection information to FortiOS
Expand Down Expand Up @@ -102,7 +106,7 @@ func bFortiManagerHostnameExist(c *Config) bool {
func createFortiOSClient(fClient *FortiClient, c *Config) error {
config := &tls.Config{}

auth := auth.NewAuth(c.Hostname, c.Token, c.CABundle, c.CABundleContent, c.PeerAuth, c.CaCert, c.ClientCert, c.ClientKey, c.Vdom, c.HTTPProxy)
auth := auth.NewAuth(c.Hostname, c.Token, c.CABundle, c.CABundleContent, c.PeerAuth, c.CaCert, c.ClientCert, c.ClientKey, c.Vdom, c.HTTPProxy, c.PassAuth, c.Username, c.Passwd)

if auth.Hostname == "" {
_, err := auth.GetEnvHostname()
Expand Down Expand Up @@ -153,6 +157,25 @@ func createFortiOSClient(fClient *FortiClient, c *Config) error {
}
}

if auth.PassAuth == "" {
_, err := auth.GetEnvPassAuth()
if err != nil {
return fmt.Errorf("Error reading PassAuth")
}
}
if auth.Username == "" {
_, err := auth.GetEnvUsername()
if err != nil {
return fmt.Errorf("Error reading Username")
}
}
if auth.Passwd == "" {
_, err := auth.GetEnvPasswd()
if err != nil {
return fmt.Errorf("Error reading Passwd")
}
}

pool := x509.NewCertPool()

if auth.CABundle != "" {
Expand Down
24 changes: 24 additions & 0 deletions fortios/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,27 @@ func Provider() *schema.Provider {
Description: "",
},

"passauth": {
Type: schema.TypeString,
Optional: true,
Default: "disable",
Description: "Enable/disable password authentication, can be 'enable' or 'disable'",
},

"username": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "",
Description: "FortiGate Username",
},

"passwd": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "",
Description: "FortiGate Password",
},

"fmg_hostname": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -1031,6 +1052,9 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
CABundleContent: d.Get("cabundlecontent").(string),
Vdom: d.Get("vdom").(string),
HTTPProxy: d.Get("http_proxy").(string),
PassAuth: d.Get("passauth").(string),
Username: d.Get("username").(string),
Passwd: d.Get("passwd").(string),
FMG_Hostname: d.Get("fmg_hostname").(string),
FMG_CABundle: d.Get("fmg_cabundlefile").(string),
FMG_Username: d.Get("fmg_username").(string),
Expand Down
5 changes: 5 additions & 0 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ The following arguments are supported:

* `http_proxy` - (Optional) HTTP proxy address. You can also specify it by the environment variable `HTTPS_PROXY` or `HTTP_PROXY`.

* `passauth` - (Optional) Enables username/password based authentication. Disables usage of `token`

* `username` - (Optional) Fortigate Username. Requires setting `passauth` to `enable`

* `passwd` - (Optional) Fortigate Password. Requires setting `passauth` to `enable`


## Configuration for FortiManager
Expand Down