In this paper, the secrecy performance of a massive multiple-input multiple-output (MIMO) non-orthogonal multiple access (NOMA) network is studied in the presence of a multiple-antenna eavesdropper. The ergodic secrecy rates for the downlink transmission in the considered system are derived to provide important insights. Then, by using these results, a joint power allocation scheme is proposed for both uplink training and downlink data transmission phases to maximize the sum ergodic secrecy rates. Because the utility function of interest is non-concave and the involved constraints are non-convex, a new iterative algorithm is proposed, which can find at least a local optimum. The obtained results reveal that the secrecy performance of NOMA networks benefits from deploying massive MIMO techniques. They also indicate that the proposed optimization algorithm enhances the secrecy performance of the considered system.